I have the following HTML code which I convert to a document object then a string again using serializeToString():
let html = `<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>Hello
</body>
</html>`;
let newHTMLDocument = new DOMParser().parseFromString( html, 'text/html' );
let head = new XMLSerializer().serializeToString(newHTMLDocument.head);
console.log(head);
Why does head contain:
<head xmlns="http://www.w3.org/1999/xhtml">
<title>Title</title>
</head>
As you can see, the xmlns="http://www.w3.org/1999/xhtml" is not in the original string, so why is serializeToString() adding this to my head tag and how can I stop the function from doing that, so the head variable contains this instead:
<head>
<title>Title</title>
</head>
<!DOCTYPE HTML>it won't do that. - user4616966