- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to access element with nth index in jQuery?
To access element with nth index from an HTML page, use the jQuery eq() method. It is used to access the index of an element in jQuery. The eq() method refers the position of the element.
Example
You can try to run the following code to access element with nth index in jQuery. Here, element with 2nd index is considered:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $('ul li').eq(2).css({'background-color':'#E6B16A'});}); </script> </head> <body> <ul> <li>India</li> <li>US</li> <li>UK</li> <li>Australia</li> </ul> </body> </html>
- Related Articles
- How to access index of an element in jQuery?
- Finding the nth power of array element present at nth index using JavaScript
- jQuery index() with examples
- How to identify nth element using xpath in Selenium with python?
- MongoDB query on nth element (variable index) of subdocument array
- How to wrap tables with div element using jQuery?
- How to wrap an existing element with another one in jQuery?
- jQuery :nth-child() Selector
- What happens if try to access an element with an index greater than the size of the array in Java?
- How to get and set form element values with jQuery?
- How to access an associative array by integer index in PHP?
- How to access an array element in C language?
- jQuery :nth-last-child() Selector
- jQuery :nth-of-type() Selector
- How to fetch nth div from an HTML page using jQuery?

Advertisements