MDN Web Docs

Value

A DocumentFragment.

Examples

Using importNode() with template content

js

const templateElement = document.querySelector("#foo");
const documentFragment = document.importNode(templateElement.content, true);
// Now you can insert the documentFragment into the DOM

The ownerDocument of template content

For <template> elements created in the context of a normal HTML document, the ownerDocument of the content is a separate, freshly created document:

js

const template = document.createElement("template");
console.log(template.content.ownerDocument === document); // false
console.log(template.content.ownerDocument.URL); // "about:blank"

If the <template> element is created in the context of a document that itself was created for the purpose of holding template content, then the ownerDocument of the content is the same as that of the containing document:

js

const template1 = document.createElement("template");
const docForTemplate = template1.content.ownerDocument;
const template2 = docForTemplate.createElement("template");
console.log(template2.content.ownerDocument === docForTemplate); // true

Specifications

Specification
HTML
# dom-template-content-dev

Browser compatibility

See also

Help improve MDN

Yes No

Learn how to contribute

This page was last modified on by MDN contributors.

Read the original on developer.mozilla.org ↗