--- title: HTMLTemplateElement.content slug: Web/API/HTMLTemplateElement/content translation_of: Web/API/HTMLTemplateElement/content ---
{{APIRef("Web Components")}}

The HTMLTemplateElement.content属性返回<template>元素的模板内容(一个 {{domxref("DocumentFragment")}}).

语法

var documentFragment = templateElement.content

示例

var templateElement = document.querySelector("#foo");
var documentFragment = templateElement.content.cloneNode(true);

规范

Specification Status Comment
{{SpecName('HTML WHATWG','scripting.html#dom-template-content','HTMLTemplateElement interface')}} {{Spec2('HTML WHATWG')}}
{{SpecName('HTML5 W3C','scripting-1.html#dom-template-content','HTMLTemplateElement interface')}} {{Spec2('HTML5 W3C')}} Initial definition

浏览器兼容性

{{Compat("api.HTMLTemplateElement.content")}}

相关链接