Why the click event does not work in this code (JSFiddle: http://jsfiddle.net/3WeP5/ ):
var holder = $("<div></div>"); $(document.body).append(holder); var btn = $("<button>Click Here</button>"); btn.click(function(){alert('clicked');}); holder.append(btn); holder.html(""); holder.append(btn);
you can replace this line:
btn.click(function(){alert('clicked');});
with (Does not work again):
btn.bind("click",function(){alert('clicked');});
and if I don't use jquery and set a javascript event like this, it works fine !!
btn[0].onclick=function(){alert('clicked');}
Why does the click event not work when I add an element (button) again and how to fix it?
source share