Use hover function to change paragraph background color - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:hover

Description

Use hover function to change paragraph background color

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
      <script>
$(document).ready(function(){
    $("p").hover(function(){
        $(this).css("background-color", "yellow");
        }, function(){/*from  ww w.  ja  va  2s  .c  om*/
        $(this).css("background-color", "pink");
    });
});

      </script> 
   </head> 
   <body> 
      <p>Hover the mouse pointer over this paragraph.</p>  
   </body>
</html>

Related Tutorials