开发者

How do I access the ID of an LI using jQuery?

开发者 https://www.devze.com 2023-01-27 17:23 出处:网络
How do I get the ID of a list element? Whenever I use this.id it gives me the ID of the parent table. Here\'s my code:

How do I get the ID of a list element? Whenever I use this.id it gives me the ID of the parent table. Here's my code:

$('*').bind('tap', function() {
    selectBrick(this.id);
 开发者_运维技巧   alert(this.id)
});


It seems your selector '*' is binding the tap event to the table. You could try to use the event object and see if what target is - this should be the DOM element that was actually subjected to the event.

$('*').bind('tap', function(event) {
    selectBrick(event.target.id);
    alert(event.target.id)
});
0

精彩评论

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