I've encountered an issue when using DOMParser
API. I noticed that it parses the <p>
tag incorrectly.
var myHtml = '<p><span><div>Hello</div></span><div>World</div></p>'
const parsed = new DOMParser().parseFromString(myHtml, 'text/html');
// parsed is:
<html>
<head></head>
<body>
<p></p>
<span><div>Hello</div></span>
<div>World</div>
<p></p>
</body>
</html>
As you can see, there's something wrong with the structure. If you switch <p>
tag with e.g. <span>
it'll work just fine. What's the issue here? Is there a specific case in the spec for parseFromString
method that is the reason?