getElementById() only works with
document. To parse your HTML can use
childNodes;
Modifying your code all little bit:
function parseHTML(html) {
var root = document.createElement("div");
root.innerHTML = html;
// Get all child nodes of root div
var allChilds = root.childNodes;
// Loop through all the child nodes and check for id = 'head'
for(var i = 0; i < allChilds.length; i++) {
// if id == 'head', you get your element
if (allChilds[i].id && allChilds[i].id == "head") {
// Remove it from root
root.removeChild(allChilds[i]);
}
}
document.body.innerHTML = root.innerHTML;
}