HTMLMetaElement: content-Eigenschaft

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.

Die HTMLMetaElement.content-Eigenschaft ruft das content-Attribut von Pragma-Direktiven und benannten <meta>-Daten in Verbindung mit HTMLMetaElement.name oder HTMLMetaElement.httpEquiv ab oder setzt es. Für weitere Informationen siehe das content-Attribut.

Wert

Ein String.

Beispiele

Lesen des Inhalts eines Meta-Elements

Im folgenden Beispiel wird ein <meta>-Element abgefragt, das ein name-Attribut mit dem Wert keywords enthält. Der content-Wert wird im Konsole-Log ausgegeben, um die Keywords des Dokuments anzuzeigen:

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

Erstellen eines Meta-Elements mit Inhalt

Im folgenden Beispiel wird ein neues <meta>-Element erstellt, dessen name-Attribut auf description gesetzt ist. Das content-Attribut legt eine Beschreibung des Dokuments fest und wird dem <head> des Dokuments hinzugefügt:

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

Spezifikationen

Specification
HTML
# dom-meta-content

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
content

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Siehe auch