Is the getPropertyValue method required to retrieve the CSS?

Could you please tell me why we need to use a method getPropertyValue

if we can only use getComputedStyle

one?

For example, this will work as I understand it:

var s = getComputedStyle(element, null).opacity;

      

This is equivalent to the following:

var s = getComputedStyle(element, null).getPropertyValue('opacity');

      

Can I use getComputedStyle

without getPropertyValue

?

+6


source to share


2 answers


As per the old DOM L2 Style is getPropertyValue

not required:

An interface CSS2Properties

is a convenience mechanism for retrieving and setting properties in CSSStyleDeclaration

. The attributes of this interface correspond to all the properties specified in CSS2 . Retrieving the attribute of this interface is equivalent to calling the getPropertyValue

CSSStyleDeclaration method on the interface. Setting an attribute on this interface is equivalent to calling a method setProperty

for CSSStyleDeclaration

.

However, no implementation is required to support, so usage getPropertyValue

was safer.

A corresponding CSS module implementation is not required to implement the interface CSS2Properties

.



But according to the new CSSOM, using camel without getPropertyValue

should work:

For each CSS property that is a supported CSS property , the subsequent partial interface applies where the camel attribute is retrieved when the CSS property is run for the IDL attribute for the property.

partial interface CSSStyleDeclaration {
    attribute DOMString _camel-cased attribute;
};

      

The attribute, camel-cased attribute

when received, must return the result of the call getPropertyValue()

, the argument of which is the result of executing the IDL attribute for the CSS property for the camel attribute.

The attribute setting camel-cased attribute

must be invoked setProperty()

with the first argument being the result of the IDL attribute trigger on the CSS property for the camel-cased attribute, the second argument of the given value, and the third argument. Any emitted emissions must be re-dumped.

Hence, getPropertyValue

no longer required to get CSS values.

+5


source


I believe this is for properties that cannot be point-like, for example background-position

. Although I guess the question is "why not use the brackets notation, ie getComputedStyle(element, null)['background-position']

?". Maybe they just need a getter method for the class (CSSStyleDeclaration).



+1


source







All Articles