Reputation: 7012
I have a table with an ID of InstrumentListGrid
. When a row is selected, it sets the class to ui-iggrid-activerow
. I want to add a jQuery event on that row for when someone clicks it.
So far I have
$("#InstrumentListGrid tr.ui-iggrid-activerow").click(function (event) {
alert("YAY!");
});
but that isn't firing. How do I bind to an element by class?
Upvotes: 3
Views: 178
Reputation: 143017
It appears that ui-iggrid-activerow
is dynamically added. Use the live()
function:
$('#InstrumentListGrid tr.ui-iggrid-activerow').live('click', function() {
alert('YAY!');
});
Upvotes: 0
Reputation: 7105
since the class is presumably added dynamically you should use .delegate()
$('#InstrumentListGrid').delegate('.ui-iggrid-activerow', 'click', function (e) {
// do stuff.
});
Upvotes: 2