Home > Net >  elem.innerHTML = "<body></body>" isn't working. Why?
elem.innerHTML = "<body></body>" isn't working. Why?

Time:05-06

let t=document.createElement('template');

t.innerHTML = "<body></body>"

var E = t.children; // HTMLCollection { length: 0 }

t.innerHTML = "<div></div>"; 
var E = t.children; // HTMLCollection { 0: div, length: 1 }

the div is getting parsed but not the body, why the body tag isn't getting parsed ?

I'm using Firefox 99.0.1 on windows 10

CodePudding user response:

Template elements are not allowed to contain body elements.

The parsing rules say that when encountering

A start tag whose tag name is "body" … if there is a template element on the stack of open elements, then ignore the token.

  • Related