HTMLMetaElement: thuộc tính content

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Thuộc tính HTMLMetaElement.content lấy hoặc đặt thuộc tính content của các pragma directive và dữ liệu <meta> được đặt tên kết hợp với HTMLMetaElement.name hoặc HTMLMetaElement.httpEquiv. Để biết thêm thông tin, xem thuộc tính content.

Giá trị

Một chuỗi.

Ví dụ

Đọc nội dung của phần tử meta

Ví dụ sau truy vấn một phần tử <meta> chứa thuộc tính name với giá trị keywords. Giá trị content được ghi vào bảng điều khiển để hiển thị từ khóa của tài liệu:

js
// given <meta name="keywords" content="documentation, HTML, web">
const meta = document.querySelector("meta[name='keywords']");
console.log(meta.content);
// "documentation, HTML, web"

Tạo phần tử meta với content

Ví dụ sau tạo một phần tử <meta> mới với thuộc tính name được đặt thành description. Thuộc tính content đặt mô tả của tài liệu và được thêm vào <head> của tài liệu:

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);

Thông số kỹ thuật

Thông số kỹ thuật
HTML
# dom-meta-content

Tương thích trình duyệt

Xem thêm