Get index of the element I clicked on relative to the jquery collection

前端 未结 2 1882
抹茶落季
抹茶落季 2021-01-14 22:35

I have a fiddle here, very simple one.

http://jsfiddle.net/tnQne/

The js I have is here

$(\'section a\').on(\'click\', function() {
    alert         


        
2条回答
  •  长发绾君心
    2021-01-14 23:04

    lonesomeday has a good way to do it but another way is:

    $('section a').on('click', function(e) {
        alert( $.inArray(e.target, $('section a')) );
    });​
    

    jsFiddle example

提交回复
热议问题