Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 313
Dan W. Avatar asked Jan 15 '23 15:01

Dan W.


1 Answers

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

Example:

document.getElementById("firefoxDiv").style.setProperty('background-color', 'red');
like image 200
Rob W Avatar answered Jan 23 '23 13:01

Rob W