Get and set element color via CSS style color - Javascript CSS Style Property

Javascript examples for CSS Style Property:color

Description

Get and set element color via CSS style color

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <div id="divid" style="color:red;">
          Test //  w w  w.  j  ava  2 s  .c om
      </div> 
      <script>
test();
    function test() {
    var color = document.getElementById("divid").style.color;
        if(color == "red") {
            document.getElementById("divid").style.color = "green";
        }
    }

      </script>  
   </body>
</html>

Related Tutorials