Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. StylePropertyMapReadOnly
  4. get()

StylePropertyMapReadOnly: get() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Theget() method of theStylePropertyMapReadOnly interface returns aCSSStyleValueobject for the first value of the specified property.

Syntax

js
get(property)

Parameters

property

The name of the property to retrieve the value of.

Return value

ACSSStyleValue object.

Examples

Let's get just a few properties and values. Let's start by creating a link inside aparagraph in our HTML, and adding a definition list which we will populate with#"https://example.com">Link</a></p><dl></dl>

We add a bit of CSS, including a custom property and an inheritable property:

css
p {  font-weight: bold;}a {  --color: red;  color: var(--color);}

We use the Element'scomputedStyleMap()to return aStylePropertyMapReadOnly object. We create an array of propertiesof interest and use the StylePropertyMapReadOnly'sget() method to get onlythose values.

js
// get the elementconst myElement = document.querySelector("a");// Retrieve all computed styles with computedStyleMap()const styleMap = myElement.computedStyleMap();// get the <dl> we'll be populatingconst stylesList = document.querySelector("#results");// array of properties we're interested inconst ofInterest = ["font-weight", "border-left-color", "color", "--color"];// iterate over our properties of interestfor (const property of ofInterest) {  // properties  const cssProperty = document.createElement("dt");  cssProperty.innerText = property;  stylesList.appendChild(cssProperty);  // values  const cssValue = document.createElement("dd");  // use get() to find the value  cssValue.innerText = styleMap.get(property);  stylesList.appendChild(cssValue);}

Specifications

Specification
CSS Typed OM Level 1
# dom-stylepropertymapreadonly-get

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp