最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I get firefox to set style attributes using style['attribute-name'] =? - Stack Overflow

programmeradmin1浏览0评论

In this example Chrome sets the background red, firefox and IE do not.

Trying:

document.getElementById("firefoxDiv").style['backgroundColor'] = "Red";

and

document.getElementById("firefoxDiv").style['background-color'] = "Red";

I would much rather be able to use the same syntax used in external CSS background-color vs inline using javascript .style.backgroundColor =

Thanks for your help!

Note: NO jQuery please.

In this example Chrome sets the background red, firefox and IE do not.

Trying:

document.getElementById("firefoxDiv").style['backgroundColor'] = "Red";

and

document.getElementById("firefoxDiv").style['background-color'] = "Red";

I would much rather be able to use the same syntax used in external CSS background-color vs inline using javascript .style.backgroundColor =

Thanks for your help!

Note: NO jQuery please.

Share Improve this question edited Sep 4, 2012 at 22:41 Zoltan Toth 47.7k12 gold badges131 silver badges138 bronze badges asked Sep 4, 2012 at 22:36 Dan W.Dan W. 631 silver badge7 bronze badges 1
  • 1 @ZoltanToth I'm confused as to if you've read the question? – jeremy Commented Sep 4, 2012 at 22:43
Add a ment  | 

1 Answer 1

Reset to default 9

Use .style.setProperty(propertyName, value [, priority]) instead of an expando property.

Example:

document.getElementById("firefoxDiv").style.setProperty('background-color', 'red');
发布评论

评论列表(0)

  1. 暂无评论