Access an element by class using jQuery
I have a table with an ID of InstrumentListGrid
. When a row is selected, it sets the class to ui-iggrid-activer开发者_开发百科ow
. 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?
since the class is presumably added dynamically you should use .delegate()
$('#InstrumentListGrid').delegate('.ui-iggrid-activerow', 'click', function (e) {
// do stuff.
});
It appears that ui-iggrid-activerow
is dynamically added. Use the live()
function:
$('#InstrumentListGrid tr.ui-iggrid-activerow').live('click', function() {
alert('YAY!');
});
精彩评论