I am creating a div using javascript and posting an ajax response into it:
var tempdiv = document.createElement('div');
tempdiv.setAttribute('id','tempcontent');
tempdiv.setAttribute('style','display:none');
tempdiv.innerHTML = xhr.responseText;
var newarticle = tempdiv.getElementsByTagName('article');
content.appendChild(newarticle);
Somehow newarticle is undefined. probably because the js cannot explore the code posted without it being posted to the page first. Any workaround for this? another way to write it?
getElementsByTagNamereturns aNodeListof elements with the specified tag name.appendChildexpects a single node.Try
content.appendChild(newarticle[0])