Questions tagged [getpropertyvalue]

getPropertyValue() is a method in the CSSStyleDeclaration interface (an object that exposes style information to be queried using JavaScript). It returns the value of the property that is passed in through its' parameter.

Description

getPropertyValue() is method in the CSSStyleDeclaration interface (an object that exposes style information to be queried using JavaScript). It returns the value of the property that is passed in through its' parameter.

Syntax

Given a stylesheet of:

div {
  font-weight: bold;
  color: red;
}

span{
  color: blue;
  font-weight: normal;
}

to get the font-weight property of the first style would be:

var value = document.styleSheets[0].cssRules[0].style.getPropertyValue('font-weight');

which returns "bold".

to get the font-weight property of the second style would be:

var value = document.styleSheets[0].cssRules[1].style.getPropertyValue('font-weight');

Notice that if the property has a dash then it must be specified as it is, instead of fontWeight, as is normally seen in JavaScript when using methods like .getElementById()

References

  1. Mozilla.org
6 questions
2
votes
1 answer

In Selenium for Python, how can I get an element's attribute rather than its property?

According to the docs, get_attribute actually returns the property rather than the attribute, unless the property doesn't exist, in which case it falls back to the attribute. get_property will always return the property. Is there a way to always get…
2
votes
2 answers

How to get child property value of a element property using selenium webdriver, NUnit and C#

I am testing websites using selenium webdriver and I am having difficulties getting the value of a property that is a child of another property. For me, this 2nd/child level is always coming back as null. When trying to get a value of an upper…
GIZNAJ
  • 501
  • 5
  • 23
0
votes
1 answer

Javascript - getPropertyValue gives wrong height

let a = document.getElementsByClassName("d1"); let b = window.getComputedStyle(a[0]); let c = b.getPropertyValue("height"); alert(c); .d1 { background-color: red; padding: 20px; }
Test test test
The above code alerts…
darkchampionz
  • 1,174
  • 5
  • 24
  • 47
0
votes
1 answer

JS: get the "real" value of CSS Custom Property

I know that this question seems to be asked 1 million time but here there is a little subtility. Imagine I have some CSS Custom Property like this: /* Yes the colors are terrible in this exemple, I know */ :root { --color_1: salmon; …
Ken La
  • 161
  • 7
0
votes
1 answer

how to get the default state of the visual in power BI embedded through javascript?

While applying the Javascript getProperty function we are getting the default value is only null value in Power BI Embedded. Is there any option where we get the default state of the each visual state in power BI?
0
votes
1 answer

getComputedStyle(element).getPropertyValue("--varName") does not work in firefox

Well, I want to use some css vars in my js code. Here is the part of my .css file and the .js code: const root = document.querySelector(":root"); const msgColor =…