Selector |
Describe |
Return |
Example |
Basic Selector |
#id |
Matches an element based on the given ID |
A single element |
$ ("#test") select an element with the ID test |
. class |
Matches the element based on the given class name |
Collection elements |
$ (". Test") Select element with test class |
Element |
Matches the element based on the given element name |
Collection elements |
$ ("P") Select all p elements |
* |
Match all elements |
Collection elements |
$ ("*") Select all elements |
Selector1,selector2,....., Selectorn |
The elements that match each selector are merged and returned together |
Collection elements |
$ ("Div,span,p.myclass") Select all Div,span and a set of elements that have a P label of class MyClass |
Hierarchy Selector |
$ ("ancestor descendant") |
Select all descendant (descendant) elements in the ancestor element |
Collection elements |
$ ("div span") Select all span elements in all div |
$ ("Parent > Child") |
Select the child element under the parent element, which is different from $ ("ancestor descendant"), and $ ("ancestor descendant") to select descendant elements |
Collection elements |
$ ("Div>span") Select the name under the DIV element to be a child element of span |
$ ("prev + next") |
Select the next element immediately after the Prev element |
Collection elements |
$ (". One+div") Select the next div element with class one |
$ ("prev~siblings") |
Select all siblings elements after the Prev element |
Collection elements |
$ ("#two ~div") Select all div sibling elements after the element with ID two |
Basic Filter Selector |
: A |
Select the first element |
A single element |
$ ("Div:first") selects the first DIV element in all DIV elements |
: Last |
Select the last Element |
A single element |
$ ("Div:last") selects the last div element in all DIV elements |
: Not (selector) |
Removes all elements that match a given selector |
Collection elements |
$ ("Input:not (. MyClass)") Select the element that class is not MyClass |
: Even |
Select the index is all the elements of an even number, the index is starting from 0 |
Collection elements |
$ ("input:event") Select INPUT element with an even number index |
: Odd |
Select the index is an odd number of all elements, the index is starting from 0 |
Collection elements |
$ ("input:odd") select an odd INPUT element for an index |
: EQ (Index) |
Select the element with index equal to index (index starting from 0) |
Collection elements |
$ ("Input:eq (1)") Select INPUT element with index equal to 1 |
: GT (Index) |
Select an element with index greater than index (index starting from 0) |
Collection elements |
$ ("INPUT:GT (1)") Select INPUT element with index greater than 1 (note: Greater than 1, excluding 1) |
: LT (Index) |
Select an element with index less than index (index starting from 0) |
Collection elements |
$ ("Input:lt (1)") Select INPUT element with index greater than 1 (note: Less than 1, excluding 1) |
: Header |
Select all the header elements, such as H1,h2,h3 |
Collection elements |
$ (": Header") Select all H1,h2,h3 in the Web page ... |
: Animated |
Select all elements that are currently executing the animation |
Collection elements |
$ ("div:animted") Select the div element that is executing the animation |
Content Filter Selector |
: Contains (text) |
Select elements with text content of "text" |
Collection elements |
$ ("Div:contains (' Me ')") Select the div element that contains the text "I" |
: Empty |
Select an empty element that does not contain child elements or text |
Collection elements |
$ (div:empty) Select a div empty element that does not contain resources (including text elements) |
: Has (selector) |
Select the element that contains the element that the selector matches |
Collection elements |
$ ("Div:has (P)") select the div element that contains the P element |
:p arent |
Select elements that contain child elements or text |
Collection elements |
$ ("div:parent") Select a DIV element that has child elements (including text elements) |
Visibility Filter Selector |
: Hidden |
Select all elements that are not visible |
Collection elements |
$ (": Hidden") selects all elements that are not visible. Including the "Input type=" hidden "/", "div style=" display:none "and" div style= "Visibility:hidden" and other elements. If you want to select only the INPUT element, you can use $ ("Input:hidden") |
: Visible |
Select all visible elements |
Collection elements |
$ ("div:visible") Select all the visible div elements |
Attribute Filter Selector |
[Attribute] |
Select the element that owns this property |
Collection elements |
$ ("Div[id]") Select the element that owns the property ID |
[Attribute=value] |
Select the element of value for the property |
Collection elements |
$ ("div[title=test]") Select a DIV element with property title "Test" |
[Attribute!=value] |
To select an element of the property that is not equal to value |
Collection elements |
$ ("div[title!=test]") Select the Divy element with the property title not equal to "test" (note: a DIV element with no attribute title is also selected) |
[Attribute^=value] |
Select the element that the value of the property starts with |
Collection elements |
$ ("div[title^=test]") Select the div element with property title starting with "Test" |
[Attribute$=value] |
Select the element that ends the value of the property |
Collection elements |
$ ("div[title$=test]") Select the div element with property title ending with "test" |
[Attribute*=value] |
Select the element with value for the property |
Collection elements |
$ ("div[titel*=test]") Select the div element containing ' test ' in the property title |
[Selector1] [Selector2] [Selectorn] |
The property selector is merged into a composite property selector that satisfies multiple conditions. Each time you choose, reduce the scope once. |
Collection elements |
$ ("div[id][title$= ' Test ']") Select the div element that owns the property ID and the property title ends with "test" |
child element Filter Selector |
: Nth-child (Index/event/odd/equation) |
Select the index child element or parity element under each parent element. (index from 1) |
Collection elements |
: EQ (index) matches only one element, and: Nth-child will match elements for each parent element, and: The Index of Nth-child (index) starts at 1, and EQ (index) is from 0. |
: Frist-child |
Select the first child element of each parent element |
Collection elements |
: First returns only a single element, and: The First-child selector matches each parent element. For example $ ("ul li:first-child"); Select the first LI element in each UL |
: Last-child |
Select the last child element of each parent element |
Collection elements |
Similarly,: Last returns only a single element, and: The Last-child selector matches the final child element for each parent element. For example $ ("ul li:last-child"); Select the last Li element in each UL |
: Only-child |
If an element is the only child element in its parent element, it will be matched. If the parent element contains other elements, it will not be matched |
Collection elements |
$ (UL Li:only-child) in the UL selection is the only element of the LI element |
Form Object Properties Filter Selector |
: Enabled |
Select all available elements |
Collection elements |
$ ("#form1: Enabled") Select all available elements within a form with ID "Form1" |
:d isabled |
Select all unavailable elements |
Collection elements |
$ ("#form2:d isabled") Select all unavailable elements in a form with id "Form2" |
: Checked |
Select all selected elements (Radio box, check box) |
Collection elements |
$ ("input:checked") selects all selected input elements |
: Selected |
Select All selected option elements (drop down list) |
Collection elements |
$ ("select:selected"); Select all selected option elements |
Form Object Properties Filter Selector |
Collection elements |
Collection elements |
Collection elements |
Collection element A |