function create(htmlStr) {
var frag = document.createDocumentFragment(),
temp = document.createElement('div');
temp.innerHTML = htmlStr;
while (temp.firstChild) {
frag.appendChild(temp.firstChild);
}
return frag;
}
function add(identifier, html){
var frag = create(html);
document.body.insertBefore(frag, document.getElementById(identifier));
}
identifier
is the string id of a tag that I've verified in developer tools exists, html
is just the fragment I want to prepend to the element denoted by said identifier
. frag
is a bonefide html fragment, and the call to getElementById
returns a bonefide element ie neither are strings. Why am I getting the above error on insertBefore
?