Skip to main content

Tedshd's Dev note

JavaScript - Converting a JavaScript string to a html object

Table of Contents

# JavaScript - Converting a JavaScript string to a html object

var str = '<div id="myDiv"></div>';
var htmlObject = document.createElement('div');
htmlObject.innerHTML = str;
/* htnkObject is obj;
<div>
	<div id="myDiv"></div>
</div>
*/

Refer - converting a javascript string to a html object