For example, if you set up onclick handler like this:
<div id="outerDiv">... the onclick handler will stop working if you change innerHtml of outerDiv, for example to add another paragraph:
<p id="para1">Click here</p>
</div>
<script>
var x = document.getElementById("para1");
x.onclick = function () { alert("Clicked"); }
</script>
<script>
var outerDiv = document.getElementById("outerDiv") ;
outerDiv.innerHtml += "<p id='para2'>Another paragraph</p>" ;
</script>
No comments:
Post a Comment