Change div element color - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Div

Description

Change div element color

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <div onclick="this.style.color = 'red'">
          Change color with inline javascript 
      </div> 
      <div onclick="changeColor(this)">
          Change color with javascript function 
      </div> 
      <script>
   function changeColor(element){
   element.style.color = 'blue';
}

      </script>  
   </body>/*w  w w .j  a  va 2  s .  c o m*/
</html>

Related Tutorials