NokX
1
I have a span tag that I use to dynamically populate with HTML elements and on occasion clear.
When I want to clear the contents of the span, this works as expected in Firefox:
document.getElementById('mySpan').innerHTML = '';
But this does nothing in IE. What’s the best way to clear out the HTML elements in a tag in IE?
That’s weird. I know innerHTML is a bit quirky in IE, but I would have thought that would have worked.
What version of IE are you using?
To answer your question:
With jQuery:
$('#mySpan').empty();
With vanilla JS:
var node = document.getElementById('mySpan');
while (node.hasChildNodes()) {
node.removeChild(node.firstChild);
}
NokX
3
Thanks! The while loop did the trick.