Hi,
I need to parse an HTML string received from an AJAX request. I wrote a function that places the HTML string into an unappended (not added) <div>
, which opens the string up to the DOM hierarchy. However, when I try to access the elements of this <div>
, I get an error in the console that says root.getElementById is not a function. This tells me that I can't access any of the child nodes.
Can anyone help? Here is what my script looks like:
function parseHTML(html) {
var root = document.createElement("div");
root.innerHTML = html;
// The error console stops at this line
if (root.getElementById("head")) {
// Parsing head...
// Functions removed (unnecessary to post)
// Parsing finished, remove tag
root.removeChild(head);
}
document.body.innerHTML = root.innerHTML;
}
Does anybody know why I can't access DOM functions with root
?