Forum : How to change style on an element?
Brief description  about Online courses   join in Online courses
View Balu  Prasad 's Profile

How to change style on an element?

Changing form elements style...
Asked by Balu Prasad | Nov 9, 2009 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Balu,

Between CSS and javascript there 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";

Hope you got your doubt cleared.
Nov 9, 2009