tickle/modules/utils/generateDomFromString.mjs
2023-05-09 04:00:53 +02:00

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;