todo list
The issue of updating web pages without flickering is relatively large.
The loaded html string (obtained through ajax), if you still need to run the code, then there must be a problem.
I hope to use a non-displayed iframe to host this object. This feels a bit like dirty work.
The final solution is
Copy the code code as follows:
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);