16 lines
413 B
JavaScript
16 lines
413 B
JavaScript
//@ts-check
|
|
|
|
/**
|
|
* Generates valid dom elements from a string
|
|
* @param {string} htmlString
|
|
*/
|
|
export const generateDomFromString = (htmlString) =>{
|
|
const children = new DOMParser().parseFromString(`<div>${htmlString}</div>`, "text/html")
|
|
.children
|
|
const fragment = document.createDocumentFragment()
|
|
fragment.append(...children)
|
|
return fragment
|
|
;}
|
|
|
|
export default generateDomFromString;
|