Beschreibung der Selectoren in jQuery / CSS

by juErik

HTML

Ähnlich wie oben Syntax und Beispielen möchte folgenden Beispiele geben Ihnen das Verständnis über die Verwendung verschiedener Arten von andere nützliche Selektoren:

$('*'): Dieser Selektor wählt alle Elemente im Dokument.

$("p > *"): Dieser Selektor wählt alle Elemente, die Kinder eines Absatzelement sind.

$("#specialID"): Diese Auswahlfunktion wird das Element mit id = "specialID".

$(".specialClass"): Dieser Selektor bekommt alle Elemente, die die Klasse haben specialClass .

$("li:not(.myclass)"): Wählt alle Elemente von <li>, die nicht über class = "myclass" abgestimmt.

$ ("A # specialID.specialClass"): Dieser Selektor passt Verbindungen mit der ID specialID und einer Klasse von Sonderklasse .

$ ("P a.specialClass"): Dieser Selektor passt Verbindungen mit einer Klasse der Sonderklasse erklärte in <p> Elementen.

$ ("Ul li: first"): Dieser Selektor wird nur die erste <li> Element der <ul>.

$ ("# Behälter p"): Wählt alle Elemente abgestimmt <p>, die Nachkommen von einem Element, das die ID hat, sind Behälter .

$ ("Li> ul"): Wählt alle Elemente von <ul> abgestimmt, die Kinder eines Elements durch abgestimmt sind <li>

$ ("Strong + em"): Wählt alle Elemente abgestimmt <em>, die unmittelbar auf ein Geschwisterelement von <strong> abgestimmt.

$ ("P ~ ul"): Wählt alle Elemente abgestimmt <ul>, die ein Geschwisterelement von <p> abgestimmt folgen.

$ ("Code, em, strong"): Wählt alle von abgestimmten Elementen <code> oder <em> oder <strong>.

$ ("P stark, .myclass"): Wählt alle Elemente abgestimmt <strong>, die Nachkommen von einem Element von <p> abgestimmt sowie alle Elemente, die eine Klasse haben, sind myclass .

$ (": Leer"): Wählt alle Elemente, die keine Kinder haben.

$ ("P: empty"): Wählt alle Elemente abgestimmt <p>, die keine Kinder haben.

$ ("Div [p]"): Wählt alle Elemente von <div>, die ein Element von <p> abgestimmt enthalten abgestimmt.

$ ("P [.myclass]"): Wählt alle Elemente abgestimmt <p>, die ein Element mit einer Klasse enthalten myclass...

CSS

.blue { color:blue; }

JavaScript

Similar to above syntax and examples, following examples would give you understanding on using different type of other useful selectors:

$('*'): This selector selects all elements in the document.

$("p > *"): This selector selects all elements that are children of a paragraph element.

$("#specialID"): This selector function gets the element with id="specialID".

$(".specialClass"): This selector gets all the elements that have the class of specialClass.

$("li:not(.myclass)"): Selects all elements matched by <li> that do not have class="myclass".

$("a#specialID.specialClass"): This selector matches links with an id of specialID and a class of specialClass.

$("p a.specialClass"): This selector matches links with a class of specialClass declared within <p> elements.

$("ul li:first"): This selector gets only the first <li> element of the <ul>.

$("#container p"): Selects all elements matched by <p> that are descendants of an element that has an id of container.

$("li > ul"): Selects all elements matched by <ul> that are children of an element matched by <li>

$("strong + em"): Selects all elements matched by <em> that immediately follow a sibling element matched by <strong>.

$("p ~ ul"): Selects all elements matched by <ul> that follow a sibling element matched by <p>.

$("code, em, strong"): Selects all elements matched by <code> or <em> or <strong>.

$("p strong, .myclass"): Selects all elements matched by <strong> that are descendants of an element matched by <p> as well as all elements that have a class of myclass.

$(":empty"): Selects all elements that have no children.

$("p:empty"): Selects all elements matched by <p> that have no children.

$("div[p]"): Selects all elements matched by <div> that contain an element matched by <p>.

$("p[.myclass]"): Selects all elements matched by <p> that contain an element with a class of myclass.

$("a[@rel]"): Selects all elements matched by <a> that have a rel attribute.

$("input[@name=myname]"): Selects all...