Dennie
asked on
jquery click function not working
Hi,
I've got the following click function:
$('.add_button').click(fun ction() {
alert(1);
});
By pressing an other button, a IMG is dynamically added:
$('.edit').click(function( ) {
td2 = $(this).parents('td').next ();
td2.prepend('<img class="add_button" src="images/add.png">');
});
Why is a new click on the dynamically added image not working?
I've got the following click function:
$('.add_button').click(fun
alert(1);
});
By pressing an other button, a IMG is dynamically added:
$('.edit').click(function(
td2 = $(this).parents('td').next
td2.prepend('<img class="add_button" src="images/add.png">');
});
Why is a new click on the dynamically added image not working?
ASKER
With prepend the img is added within the td, so that's not the problem. Can't share the entire html structure, its too much. But I'm pretty sure that's not the problem...
Your solution with html() doesn't work. any other ideas?
Your solution with html() doesn't work. any other ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use
$('.add_button').live('click',function(){
alert(1);
});
ASKER
Nice!
also i quess, you are prepending the img at td level, which rather should be inside that td
please try to make it
$('.edit').click(function(
td2 = $(this).parents('td').next
var innerHTML = td2.html();
td2.html('<img class="add_button" src="images/add.png"/>' + innerHTML );
});