HOW TO CHANGE STYLE ON AN ELEMENT?

Awadhendra Tiwari

Total Post:510

Points:2550
Posted by  Awadhendra Tiwari
 1769  View(s)
Ratings:
Rate this:
  1. Awadhendra Tiwari

    Post:510

    Points:2550
    How to change style on an element?

    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";

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!