I have the following function:
function parseMarkupToDOM(markup) {
return new DOMParser().parseFromString(markup, "text/html").body.firstElementChild;
}
When passing most elements, it works just fine. For instance:
parseMarkupToDOM(`<button>myButton</button>`); // returns a proper DOM element
parseMarkupToDOM(`<h1>myHeading</h1>`); // returns a proper DOM element
However, when I try to parse a thead
into a DOM element, I get null
:
parseMarkupToDOM(`
<thead>
<tr></tr>
<tr></tr>
</thead>
`); // returns null
I thought that maybe thead
cannot be the child of body
, but I am not sure how to get around it, and was not able to find any useful information about this issue. Any idea?