How to change CSS property using JavaScript

You can use style property for this. For example, if you want to change border –

document.elm.style.border = "3px solid #FF0000";

similarly for color –

 document.getElementById("p2").style.color="blue";

Best thing is you define a class and do this –

document.getElementById("p2").className = "classname";

(Cross Browser artifacts must be considered accordingly).

Leave a Comment