Home > DeveloperSection > Interviews > How to change style on an element?

Posted on    May-18-2011 9:37 AM

 JavaScript JavaScript 
Ratings:
 1 Answer(s)
  1547  View(s)
Rate this:

Awadhendra Tiwari

Total Post:510

Points:2550
Posted on    May-18-2011 12:00 AM

Between CSS and javascript is a weird symmetry. CSS style rules are layed on top of the DOM. The CSS property names like "font-weight" are transliterated into "myElement.style.fontWeight". The class of an element can be swapped out. For example:
document.getElementById("myText").style.color = "green";
document.getElementById("myText").style.fontSize = "20";
-or-
document.getElementById("myText").className = "regular";

Don't want to miss updates? Please click the below button!

Follow MindStick