New issue
Advanced search Search tips

Issue 818792 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Mar 2018
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



Sign in to add a comment

template.insertAdjacentHTML() not consider as a part of template.contant

Reported by pery.mi...@gmail.com, Mar 5 2018

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3346.8 Safari/537.36

Steps to reproduce the problem:
1. tmpl = document.createElement('template') 
2. tmpl.insertAdjacentHTML('afterbegin','<div> foo </div>')
3. tmpl.content

What is the expected behavior?
tmpl.content should return a document-fragment that contain 
'<div> foo </div>'. 
or tmpl.innerHTML should be equal to `<div> foo </div>`

What went wrong?
tmpl.content return empty document-fragment
and tmpl.innerHTML are empty 

Did this work before? No 

Does this work in other browsers? N/A

Chrome version: 66.0.3346.8  Channel: stable
OS Version: 10.0
Flash Version:
 
reportbug.js
116 bytes View Download

Comment 1 by woxxom@gmail.com, Mar 5 2018

This is working as intended according to the specification:
https://html.spec.whatwg.org/multipage/scripting.html#the-template-element

  > The template contents of a template element are not children of the element itself.
  > It is also possible, as a result of DOM manipulation, for a template element to contain Text nodes and element nodes; 
    however, having any is a violation of the template element's content model, since its content model is defined as nothing.

The proper code should use the "content" property:

  tmpl.content.firstElementChild.insertAdjacentHTML('beforebegin','<div> foo </div>')
  tmpl.content.querySelector('*').insertAdjacentHTML('beforebegin','<div> foo </div>')

The second line is Safari/Edge-compatible.
 Issue 818791  has been merged into this issue.
Labels: Needs-Triage-M66
Status: WontFix (was: Unconfirmed)
Since this is according to spec, I'm closing the issue.

Sign in to add a comment