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

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

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?

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?

Share Improve this question asked Feb 20, 2012 at 16:11 David GDavid G 96.9k41 gold badges172 silver badges258 bronze badges 1
  • This behaviour persists in IE11 and FF 36.01 but Chrome 40.0.2214.115 works as expected and returns the assembled short-hand style. – Cool Blue Commented Mar 14, 2015 at 3:37
Add a ment  | 

1 Answer 1

Reset to default 8

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742360698a4429333.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信