I have this simple code. http://jsfiddle.net/borth/BmEZv/ If you click on a link once, it works fine. If you click on it a second time, it will not work. Due to the fact that html loads in html after loading the DOM, I tried .on, .bind, .delegate and .live. None of them work, except for .live, which is deprecated (I am using jquery 1.7.2).
Can someone explain why .live is the only function that works and why others do not work (or if I am doing something wrong with other functions).
$(document).ready(function(){ $(".OpenPopup").bind('click', function(e){ alert('test .OpenPopup'); // do something return false; }); $(".EditIcon").bind('click', function(){ alert('test .EditIcon'); // do something $("#ABC").html('<div class="EditIcon OpenPopup" pwidth="800" pheight="500" ptitle="EditText">click here again</div>'); }); }); <div id="ABC"><div class="EditIcon OpenPopup" pwidth="800" pheight="500" ptitle="EditText">click here</div></div>
Brandon orth
source share