jquery - How can I check the number of the item that was clicked -


let's have many items click event (all have same element name , possibly same class).

<a>a</a> <a>b</a> <a>c</a> <a>d</a> 

then have method triggered on click event. how can check number of item clicked?

in example if 'c' clicked should 3 answer.

you can use .prevall():

$('a').click(function() {     alert($(this).prevall('a').length + 1); }); 

or .index():

$('a').click(function() {     alert($(this).index() + 1); }); 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -