Elliot Bonneville
Elliot Bonneville

Reputation: 53291

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

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)
});

Upvotes: 0

Views: 135

Answers (1)

Martin Algesten
Martin Algesten

Reputation: 13620

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)
});

Upvotes: 1

Related Questions