Home >Web Front-end >JS Tutorial >In jQuery: last-child selector usage example_jquery
The example in this article describes the usage of the :last-child selector in jQuery. Share it with everyone for your reference. The specific analysis is as follows:
This selector matches the last child element of the parent element.
Note that :last only selects one element, and this selector will match the last child element of each parent element.
Grammar structure:
This selector is generally used in conjunction with other selectors, such as class selectors, element selectors, etc. For example:
The above code can set the font color in the last li element under the parent element to blue.
Note: It is necessary to explain the concept in combination with the above code. The parent element mentioned here is not li, but the parent element of li. Many people often mistakenly think that it matches the last element among the child elements of the li element.
Example code:
I hope this article will be helpful to everyone’s jQuery programming.