CSSStyleDeclaration: length-Eigenschaft

Baseline Widely available

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

Die schreibgeschützte Eigenschaft gibt eine ganze Zahl zurück, die die Anzahl der Stildeklarationen in diesem CSS-Deklarationsblock darstellt.

Wert

Eine ganze Zahl, die die Anzahl der Stile angibt, die explizit auf dem Elternteil der Instanz gesetzt sind.

Beispiele

Das Folgende ermittelt die Anzahl der explizit gesetzten Stile auf dem folgenden HTML-Element:

html
<div
  id="div1"
  style="margin: 0 10px; background-color: #CA1; font-family: monospace"></div>

JavaScript-Code:

js
const myDiv = document.getElementById("div1");
const divStyle = myDiv.style;
const len = divStyle.length; // 6

Spezifikationen

Specification
CSS Object Model (CSSOM)
# dom-cssstyledeclaration-length

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
length

Legend

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

Full support
Full support