Styling parent of active element for background color - Javascript CSS Style Property

Javascript examples for CSS Style Property:backgroundColor

Description

Styling parent of active element for background color

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <div> 
         <a href="#" id="x"> content </a> 
      </div> 
      <script type="text/javascript">
    document.addEventListener("mousedown",function(e){
        e.target.parentElement.style.backgroundColor="red";
    });/*ww  w  .j a  v a2 s.  c o m*/
    document.addEventListener("mouseup",function(e){
        e.target.parentElement.style.backgroundColor="";
    });

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

Related Tutorials