Let's say I have an element
and I am interested in finding out its background-position
:
To achieve this, I use the following code snippet:
window.getComputedStyle(element).getPropertyValue('background-position')
If the value of background-position is not explicitly defined for that element
, the result would be:
0% 0%
However, if I were to set the background-position
to 0% 0%
, the returned result would still be the same.
So, how can I differentiate between these two scenarios? How can I determine whether the attribute is truly defined or not?
EDIT:
Some may suggest using
style.getPropertyValue('background-position')
, but this approach only considers inline values. What I'm looking for is a way to also take into account whether the value has been specified in an external CSS file. http://dev.w3.org/csswg/cssom/#elementcssinlinestyle