The function existed, but the element didn't exist inside the container,
so there was no element to bind the click to.
You can check this for yourself by doing alert($(".new_button").length)
just after both lines that you have listed.
So.....
1) Try adding the $(".new_button").click(.....) line immediately after
the $("#container").html(.....) line, or else
2) Look at livequery, which might do the trick.
L
nick wrote:
So, if a user clicks a button, I set a function to create a new class
like
$("#container").html('<a href="" class="new_button">Click</a>');
and I preloaded ( which means, this function existed before the button
was created) a function like
$(".new_button").click(function(){ alert('succeed'});
When I click the button, nothing happens. I also used $
(".new_button").addClass functionalitiy to test it..
What would be the ideal solution in this case?
------------------------------------------------------------------------
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.329 / Virus Database: 270.12.27/2112 - Release Date: 05/13/09 07:04:00