Is there a way to convert markup string to node object in JavaScript? Actually I am looking for the subsitute for:
document.getElementById("divOne").innerHTML += "<table><tbody><tr><td><input type='text' value='0' /></td></tr></tbody></table>"
something like
document.getElementById("divOne").appendChild(document.createNodeFromString("<table><tbody><tr><td><input type='text' value='0' /></td></tr></tbody></table>"))
using createNodeFromString rather creating the table element then append its child elements then attach their respective attributes and values!
There’s not an existing cross-browser function for this. The following method can be used to achieve the desired effect (using a
DocumentFragmentfor an optimized performance, based on this answer):Usage (indention for readability):