JunM
JunM

Reputation: 7160

JQuery dynamic binding on table row

I am having problem regarding the bindings on table. The id is dynamic assuming the event.id is correct.

If I do it this way, the alert will fire.

$('#grid' + event.id).one("click", function(e) {
    $('tr').click(function(ev) {
         $(this).attr('id');
    });
});

In this way, the alert won't fire. I don't know what is wrong with this code, if I combine the id and tr.

$("#grid" + event.id+" tr").one( "click", function(ev) { 
         $(this).attr('id');
});

Upvotes: 0

Views: 61

Answers (1)

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28513

Try this:

$("#grid" + event.id).one("click","tr", function(e) { 
         $(this).attr('id');
});

Upvotes: 1

Related Questions