jQuery
HTML
CSS
JavaScript
PHP
SQL
WordPress
jQuery Reference

Quick Reference

The index() method returns the index position of specified elements relative to other specified elements, and if not found, will return -1.

				
					$('li').index();
				
			

Syntax

				
					$(selector).index(element)
				
			
				
					/* shows the index value of each list item */
$('li').click(function() {
    alert($(this).index());
});
				
			
				
					/* searching the DOM for an #id and getting the index of the list item */
var listItem = document.getElementById('bar');
alert('Index: ' + $('li').index(listItem));
				
			
				
					/* searching for a jQuery object and getting the index of the list item */
var listItem = $('#bar');
alert('Index: ' + $('li').index(listItem));
				
			

Parameter

ParameterDescription
elementSpecifies the element to get the index position of; it can be a DOM element or a jQuery selector

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.

jQuery
HTML
CSS
JavaScript
PHP
SQL
WordPress

Why 1SMARTchicken?

This site was built and is maintained to benefit my autistic son.
See More →

My Son's Name is Johnny

He was diagnosed as autistic quite late, at age four...
His story

Buy Me a Coffee

Thanks for your support!

Feedback

If you see an error on the page or the code itself is incorrect or incomplete, or just plain wrong, please let us know. We’re always learning. NOTE: we do not sell your information and will not send you spam emails.