javascript - jQuery selector not firing after dynamically adding a row to a table -
i have table
<table id="table1"> <tr> <td>cell 1</td> <td>cell2</td> </tr> </table> on selecting cell
$('#table1 tr td').bind('click', function(){ alert('selected'); }) however, when add cell dynamically
$(this.parentnode).after('<tr><td>cell 3</td><td>cell 4</td></tr>'); now, when click cell 3 or cell 4, alert message not fired.
how can fixed without refreshing page?
user jquery "on" method instead of bind. https://api.jquery.com/on/ it's main dif bind performs kind of watch element in selector , add 'live bind'. here sample: http://jsbin.com/yapiheju/1/edit
Comments
Post a Comment