Handle Button Onclick to change its background color - Javascript CSS Style Property

Javascript examples for CSS Style Property:backgroundColor

Description

Handle Button Onclick to change its background color

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function derp() {/*  w w  w .  java2 s  .co  m*/
  document.activeElement.style.backgroundColor = '#B2DD28';
}

      </script> 
   </head> 
   <body> 
      <button type="button" onclick="derp()">time:</button> 
      <button type="button" onclick="derp()">length:</button> 
      <button type="button" onclick="derp()">position:</button>  
   </body>
</html>

Related Tutorials