Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

convert a string to html element in js

/**
 * Convert a template string into HTML DOM nodes
 * @param  {String} str The template string
 * @return {Node}       The template HTML
 */
var stringToHTML = function (str) {
	var parser = new DOMParser();
	var doc = parser.parseFromString(str, 'text/html');
	return doc.body;
};
Source by gomakethings.com #
 
PREVIOUS NEXT
Tagged: #convert #string #html #element #js
ADD COMMENT
Topic
Name
5+2 =