tickle/modules/utils/generateDomFromString.mjs

16 lines
413 B
JavaScript
Raw Normal View History

2023-05-09 02:00:53 +00:00
//@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;