tags:

views:

23

answers:

2

hi,all

I have an html table with a few rows, I have included a jquery function as

$('tr').mouseover(function() {
  $(this).addClass('row_over');
});

so that on mouse over the css class of that particular row changes. then I have added one more row using jquery, but the mouse over function doesn't work on the dynamically added row, mouse over function works in all rows except this new one.

Please help me to sortout this issue

Thank you

+3  A: 

Instead of using .mouseover, you need to use .live

$('tr').live('mouseover', function() {
  $(this).addClass('row_over');
});

However be careful using the .live() method has there's a performance hit for using it.

If you can, when adding the new row, try binding a new mouseover to that row dynamically:

row = addNewRow();
row.mouseover(function() { ... });
Ben Rowe
Thank you, it is working now :)
milan
Would it be safer to use mouseover() instead of live(), and to bind the function to the new table rows as they are created?
Carson63000
@Carson63000 that's what I said in my post.
Ben Rowe
@milan: If it works now, please accept the answer. Among other things, that marks the question as answered in the overview.
Christopher Creutzig
A: 

Use the .live event to bind to elements created after page load.

griegs
Thank you, it is working now :)
milan