Interactive change of background color by typing hex values - Javascript CSS Style Property

Javascript examples for CSS Style Property:color

Description

Interactive change of background color by typing hex values

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <input type="text" value="#330000" id="color">
      <button id="changeColor">Change Color</button> 
      <script>
var button = document.getElementById("changeColor");
button.addEventListener('click', setColor, false);
function setColor(){//  ww  w .j  a  v  a2s. co m
  var color = document.getElementById("color").value;
  document.body.style.backgroundColor = color;
}

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

Related Tutorials