Hi,
I am trying to create a new Element in my javascript code and append it to one of my elements. But it seems that old IE browsers do not support this function and my code breaks on the line where I use appendChild function.
var child = document.createElement('span');
child.innerHTML = "Hello World!"; // Crashes here
parent.appendChild(child); // And here
Is there any alternatives I can use for IE?
Thank you.
P.S the code works fine in modern browsers.
UPD: The following code solves last part of my problem, I can append empty child to a 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 of child element. createTextNode
, innerHTML
, setAttributes
do not work.