简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM