Check element background value - Javascript CSS Style Property

Javascript examples for CSS Style Property:background

Description

Check element background value

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {//from   w w  w .  j  a  va2s.co  m
var foo = document.getElementById("foo");
foo.onclick = function(){
        if(foo.style.background!="yellow")
           foo.style.background = "yellow";
        else if(foo.style.background =="yellow")  
           foo.style.background = "pink";
};
    });

      </script> 
   </head> 
   <body> 
      <p id="foo">Hello, people!</p>  
   </body>
</html>

Related Tutorials