From: http://bytes.com/topic/javascript/answers/743778-please-help-me-updating-dom-element-javascript-contents

How to add code with createTextNode using “appendChild” to a “<script>”.

Fact is, as of right now- 2010/05/17 with the Internet Explorer 8 and below you cannot use the “document.createTextNode()” and append it to a “document.createElement(‘script’)”.

So the code below will allow you to by default use the normal method and fallback to IE’s method.

For IE you must use the .TEXT.

Eg: document.createElement(‘script’).text=”TEST CODE”;

document.newScript= function(s){
var el= document.createElement(‘script’);
el.type= ‘text/javascript’;
try{
el.appendChild(document.createTextNode(s));
}
catch(er){
el.text= s;
}
return document.getElementsByTagName(‘head’)[0].appendChild(el);
}

 745 total views