Reputation: 35
I am added json object data and three buttons for every li tag in my webpage. My requirement is , I want to get that dynamically added button . But i am not getting that button by using script below
$("but1").click(function(){
alert("hi iam getting dynamic added button");
});
So please give me some suggession to acheive this.
Upvotes: 2
Views: 597
Reputation: 382666
You need the live()
method for dynamic generated elements:
$("#but1").live('click', function(){
alert("hi iam getting dynamic added button");
});
live()
Description: Attach a handler to the event for all elements which match the current selector, now or in the future.
Upvotes: 0
Reputation: 186552
$('#selector').live('click', function(){} )
Since they don't exist, you need to use live or delegate
Upvotes: 3