On() Method

The on() method attaches one or more event handlers for selected elements.

Code Structure:
$(document).ready(function(){
  $('p').on({
    mouseenter: function(){
      $(this).css("background-color", "lightgray");
    },
    mouseleave: function(){
      $(this).css("background-color", "lightblue");
    },
    click: function(){
      $(this).css("background-color", "yellow");
    } 
  });
}); 

Share this

Related Posts