javascript - What's the difference between object.setAttribute() and object.style? -


they same thing, why need both? or setattribute used things other style?

object.setattribute("style","background-color:#ffffff"); 

is equal to

object.style.backgroundcolor = "#ffffff"; 

and better or more convenient use?

setattribute 

can used set any attribute of object, including not limited style.

style.<style> = value 

is used set or modify style.

in example give same setattribute works on browsers newer versions of ie (9+). object.style more cross browser compliant.


Comments