David G
David G

Reputation: 96810

Why does getPropertyValue return an empty string instead of the element's style property?

This seems to only happen when I use "background" in the parameters of getPropertyValue();:

var d = document.getElementById('myDiv');

window.getComputedStyle(d).getPropertyValue('background'); // ""

Why does it return an empty string and how can I get this to return the actual background css property?

Upvotes: 3

Views: 5211

Answers (1)

Elian Ebbing
Elian Ebbing

Reputation: 19037

According to this page, at least the mozilla browser returns null when requesting the value of shorthand properties. So it seems have to query the different properties of the background style separately:

window.getComputedStyle(d).getPropertyValue('background-color');
window.getComputedStyle(d).getPropertyValue('background-image');
// etc.

Edit: it looks like it is a known bug

Upvotes: 8

Related Questions