get element index jquery code example

Example 1: jquery each get index

$( "li" ).each(function( index ) {
  console.log( index + ": " + $( this ).text() );
});

Example 2: jquery index of element

$("#wizard li").click(function () {
    console.log( $(this).index() );
});

Example 3: jquery find index of this

$(document).ready(function() {

    $("#example div").click(function() {
        var index = $("#example div").index(this);
        $("#example_index").html("Index " + index + " was clicked");
    });
   
});

Example 4: jquery get element by index

$('ul li').eq(index).css({'background-color':'#343434'});