How to find index of Selected element
jQuery provides index() method to find out index of any element. index() method returns an integer value that indicates position of the element. If the element is not found then it returns -1. The index value starts from 0 which means 1st element value will be 0.
See below code snippets which finds the index of the click tr element in the table.
$(document).ready(function(){ $('table tr').mouseover(function(){ $(this).css("cursor","pointer"); }); $('table tr').click(function(){ var index = $('table tr').index(this); alert('You Clicked row ' + index); }); });
If you don't pass any argument in the index function then it will always return position of first element, which is 0.
Feel free to contact me for any help related to jQuery. I will gladly help you.