开发者

jQuery's delegate() method, index number of the current element?

开发者 https://www.devze.com 2023-01-22 22:47 出处:网络
Using jQuery\'s delegate() method, can I get the index number of the current element? For example: $(\'#tracks\').delegate(\'.track-item\', \'click\', function(e) {

Using jQuery's delegate() method, can I get the index number of the current element?

For example:

$('#tracks').delegate('.track-item', 'click', function(e) {
    e.preventDefault();
    alert(开发者_高级运维$('.track-item').index(this));
});

Does anyone have an elegant solution to this?


What you have works, you can see it in action here.

The alternative form is:

alert($(this).index('.track-item'));

You can try that one here.


That should work perfectly fine. What's the problem?

0

精彩评论

暂无评论...
验证码 换一张
取 消