Is there a difference between getPropertyValue() and the bracket notation [] for CSSStyleDeclaration?
One difference is that getPropertyValue
is guaranteed to return a string, while with the direct property access (JavaScript's bracket or dot notation) you could get undefined
. getPropertyValue
will return the empty string in that case.
let el = document.querySelector('body');
let style = window.getComputedStyle(el);
console.log(style.something === style.getPropertyValue('something')); // false