I have a table with and id of foo and I want to add rows dynamically that have a button that do something. How can I assign the listeners for the buttons dynamically using JQuery?
Thanks
I have a table with and id of foo and I want to add rows dynamically that have a button that do something. How can I assign the listeners for the buttons dynamically using JQuery?
Thanks
You can use the bind
method to assign event listeners if your buttons are already present or use the live
or delegate
methods if the buttons are generated dynamically.
Try with live()
method:
$('.edit').live('click', function(){
// your code here...
});
you can assign class to dynamically added buttons and write something like if class is adder
$(function(){
$(".adder").live("click",function(){
//do something
});
});