Finding Dom Node Index for elements of a certain class

后端 未结 2 590
旧时难觅i
旧时难觅i 2021-01-23 01:29

Hi I have a series of tags with different classes. When a span is clicked I want to return the index of the class of spans. So not the index of the spans themselves.

He

2条回答
  •  时光取名叫无心
    2021-01-23 02:04

    Try,

    $( "span" ).click(function() {
        var index = $('.' + $(this).attr('class')).index($(this));
        alert(index + 1);
    });
    

    DEMO

提交回复
热议问题