"Cannot get value of property" appendChild ": object is null or undefined" when adding script in IE

When I try to add the following IE script in IE, I get this error:

"Error: could not get the value of the appendChild property: the object is null or undefined"

It works fine in Chrome, but when testing on IE9 this happens. Can someone tell me what a mistake is?

// create script in document var fbScript = document.createElement("script"); fbScript.type = "text/javascript"; // make script source the facebook plugin fbScript.src = "http://connect.facebook.net/en_US/all.js#xfbml=1"; // append script to appropriate tab document.getElementById('Tab' + tab_counter).appendChild(fbScript); 
+6
javascript dom internet-explorer facebook blogger
Aug 24 2018-11-11T00:
source share
1 answer

This can happen if your javascript code is run before all parts of the HTML are loaded. Try putting this code in a function and running it on the onload event. or use the more elegant onload jQuery event. This is something like this.

 $().ready(function () { var fbScript = document.createElement("script"); fbScript.type = "text/javascript"; // Make script source the facebook plugin fbScript.src = "http://connect.facebook.net/en_US/all.js#xfbml=1"; // Append script to appropriate tab document.getElementById("Tab" + tab_counter).appendChild(fbScript); }); 
+10
Aug 24 2018-11-11T00:
source share



All Articles