var str2DOMElement = function(html) { var frame = document.createElement('iframe'); frame.style.display = 'none'; document.body.appendChild(frame); frame.contentDocument.open(); frame.contentDocument.write(html); frame.contentDocument.close(); var el = frame.contentDocument.body.firstChild; document.body.removeChild(frame); return el; } var markup = '<div><p>text here</p></div>'; var el = str2DOMElement(markup);