AppendChild in older IE browsers
I am trying to create a new element in my javascript code and add it to one of my elements. But it seems like older IE browsers don't support this feature and my code breaks down to a line where I use the appendChild function.
var child = document.createElement('span');
child.innerHTML = "Hello World!"; // Crashes here
parent.appendChild(child); // And here
Are there any alternatives that I can use for IE?
Thank.
PS the code works fine in modern browsers.
UPD: The following code solves the last part of my problem, I can add an empty parent parent:
var child = document.createElement('span');
if (parent.insertAdjacentElement){
parent.insertAdjacentElement('beforeEnd', child);
}
else if (parent.appendChild) {
parent.appendChild(child);
}
But I still need to put some data inside the child. createTextNode
. innerHTML
, setAttributes
do not work.
source to share
It may be unrelated, but please check this link for how someone else solved this problem
Edit: and this link too
source to share