In Jquery how do you find out the 'eq' of an element of what is being clicked? In Jquery how do you find out the 'eq' of an element of what is being clicked? jquery jquery

In Jquery how do you find out the 'eq' of an element of what is being clicked?


$('#uploadChoice div').click(function(event) {  var index = $(this).index();});


An easier alternative that does not require duplicating a selector is the following

$('#uploadChoice div').click(function(event) {  var index = $(this).prevAll().length;});


You can add selectors as well, and pass "$(this)" as argument:

$(document).on('click', 'button.testbutton', function () {    var index = $('div.example > div.xyz').find('button.testbutton').index($(this));});