Javascript examples for jQuery Method and Property:eq
The eq() method gets element by index number among the selected elements.
The index numbers start at 0.
Parameter | require | Description |
---|---|---|
index | Required. | index of the element. |
index can either be a positive or negative number.
Negative number will start the index count from the end of the selected elements.
The following code shows how to Select the second <p> element (index number 1):
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").eq(1).css("background-color", "yellow"); });/*from w ww.j ava 2s. c o m*/ </script> </head> <body> <p>test</p> <p>test</p> <p>test</p> <p>test</p> <p>test</p> <p>test</p> <p>test</p> <p>test</p> </body> </html>