tags:

views:

8

answers:

2

Hi,

i'm adding rows to table dynamically, but the problem is i'm not able to select or activate when i click on the added rows, bellow is my code. same code is working for static rows.

$('.dataGrid tr').bind('click', function(){ $('.dataGrid tr').removeClass('active'); $(this).addClass('active');
});

$('').appendTo(table) .append($('').text(pos.posId)) .append($('').text(pos.posName)) .append($('').text(pos.posAddress));

please help me..

A: 

You need the live() method there instead of click for dynamically generated elements.

$('.dataGrid tr').live('click', function(){
  $('.dataGrid tr').removeClass('active');
  $(this).addClass('active');       
});
Sarfraz
A: 

Adding new rows to a table does not automatically add the event listener you need.

Create a function that does two things: 1. Add/insert a row to the table. 2. Bind the same event listener to that row, that you are binding to the static rows.

Symen Timmermans