Home Get Index of Span if based on the class available
When I click on the span I want to get the index of span comparing to all other spans having same class , Which means.. Click on before last span I need the index as 4 This is the code I am using to take now. var selector = $(this); var selectIndex = selector.index(); Jishad 2# Jishad Reply to 2018-01-13 10:14:34Z  var selectIndex = selector.parent().children('span.available').index(selector); bRIMOs 3# bRIMOs Reply to 2018-01-13 10:23:51Z  you should passe the current element to index() to get it's index from all the current available span so you can get the index by using$("span.available").index($(this)) PS: avoid using attribute directly on you html tag , you have to use the data- for both seatid and seatname => (data-seatid , data-seatname ) , you can access those by using dataset or data() in jquery See below snippet$(function() { $("span.available").on("click",function(){ console.log("index : " +$("span.available").index($(this)) + " seatid: "+$(this).data('seatid') ); }) }) span { display:block; } .as-console-wrapper { max-height:75px; }