HTMLMetaElement: content 屬性
HTMLMetaElement.content 屬性用於獲取或設定pragma指令和命名 <meta> 資料中的 content 屬性,它與 HTMLMetaElement.name 或 HTMLMetaElement.httpEquiv 結合使用。更多資訊,請參閱 content 屬性。
值
字串。
示例
讀取 meta 元素 content
以下示例查詢一個包含 name 屬性值(值為 keywords)的 <meta> 元素。content 值被記錄到控制檯,以顯示文件的 keywords。
js
// given <meta name="keywords" content="documentation, HTML, web">
const meta = document.querySelector("meta[name='keywords']");
console.log(meta.content);
// "documentation, HTML, web"
建立帶有 content 的 meta 元素
以下示例建立了一個新的 <meta> 元素,其 name 屬性設定為 description。content 屬性設定了文件的描述,並被新增到文件的 <head> 中。
js
const meta = document.createElement("meta");
meta.name = "description";
meta.content =
"The <meta> element can be used to provide document metadata in terms of name-value pairs, with the name attribute giving the metadata name, and the content attribute giving the value.";
document.head.appendChild(meta);
規範
| 規範 |
|---|
| HTML # dom-meta-content |
瀏覽器相容性
載入中…