C
cantrell78
I can't for the life of me figure out how to execute javascript inside
of div that was set using innerHTML or in my case using cloneNode and
replaceChild (not my idea to do this, I'm just fixing it). I have
tried it with and without the defer attribute. It will work fine in
firefox, but not IE.
<script type="text/javascript">
function setInnerHTMLAndExecScript (element, html) {
var newElement = element.cloneNode(false);
newElement.innerHTML = html;
element.parentNode.replaceChild(newElement,
element);
}
function loadDiv() {
var myHtml = '<script type="text\/javascript"
defer="defer">function testMe() {alert(\'test called\')}<\/
script><input type="button" value="test me" onclick="testMe();">';
setInnerHTMLAndExecScript(document.getElementById('myDiv'),myHtml);
}
</script>
<body onload="loadDiv();">
<div id="myDiv"></div>
</body>
of div that was set using innerHTML or in my case using cloneNode and
replaceChild (not my idea to do this, I'm just fixing it). I have
tried it with and without the defer attribute. It will work fine in
firefox, but not IE.
<script type="text/javascript">
function setInnerHTMLAndExecScript (element, html) {
var newElement = element.cloneNode(false);
newElement.innerHTML = html;
element.parentNode.replaceChild(newElement,
element);
}
function loadDiv() {
var myHtml = '<script type="text\/javascript"
defer="defer">function testMe() {alert(\'test called\')}<\/
script><input type="button" value="test me" onclick="testMe();">';
setInnerHTMLAndExecScript(document.getElementById('myDiv'),myHtml);
}
</script>
<body onload="loadDiv();">
<div id="myDiv"></div>
</body>