Home >Web Front-end >JS Tutorial >jQuery: eq() selector usage example_jquery
The example in this article describes the usage of:eq() selector in jQuery. Share it with everyone for your reference. The specific analysis is as follows:
This selector matches an element with a given index value.
The position index of the element starts from 0.
Grammar structure:
This selector is generally used in conjunction with other selectors, such as class selectors, element selectors, etc. For example:
The above code sets the font color in the li with index 1 (that is, the second li) in the li element collection to green.
If not used with other selectors, the default state is to be used with the * selector, for example, $(":eq()") is equivalent to $("*:eq()").
Parameter list:
Example code:
Example 1:
The above code can set the font color in the li element with an index value of 1 in the li element collection to green. Because the index value starts from 0, the above code sets the font color in the second li is green.
Example 2:
Script House welcomes you
Since the above code does not specify a selector to be used with the :eq() selector, it is used with the * selector by default, which can match all elements, so that the element with an index value of 10 will be used. The font color is set to green.
I hope this article will be helpful to everyone’s jQuery programming.