This article mainly introduces the usage of the jQuery subattribute filter selector. examples include: first-child, last-child, nth-child, and ,: only-chilid and other sub-attribute filtering selector usage tips. For more information about jQuery sub-attribute filtering selector usage, see the following example. Share it with you for your reference. The specific analysis is as follows:
1.: first-child selector
Select all elements of the first child element of the parent level. format:
The code is as follows:
$ ("Selector: first-child ")
For example:
The code is as follows:
$ ("Ul: first-child" ).css ("text-decoration", "underline" ).css ("color", "blue ");
2.: last-child selector
Used to select all the elements of the last child element of the parent level. format:
The code is as follows:
$ ("Selector: last-child ")
For example:
The code is as follows:
$ ("Ul: last-child" ).css ("text-decoration", "underline" ).css ("color", "red ");
3.: nth-child selector
Select the nth child or parity element under the parent element.
Syntax format:
The code is as follows:
$ ("Selector: nth-child (index/even/odd/equation )");
For example:
The code is as follows:
$ ("Ul li: nth-child (4)" ).css ("color", "red "); // set the text color of the 5th elements under the ul element to red, that is, the index value of the li element is 4.
4.: only-chilid selector
The unique selector used to select an element.
Format:
The code is as follows:
$ ("Selector: only-chilid ")
Simple example:
The code is as follows:
Child element filter selector