Alex Rivera | Logout

Get index of clicked element in collection with jQuery

Asked 2011-04-04T22:59:32.273
72

How do I get the index of clicked item in the code below?

$('selector').click(function (event) {
    // get index in collection of the clicked item ...
});

With Firebug I saw this: jQuery151017197709735298827: 2 (I've clicked in the second element).

Edit
Report

1 Answer

67
$('selector').click(function (event) {
    alert($(this).index());
});

jsfiddle

answered 2011-04-04T23:17:47.087

Your Answer