Tuesday, July 11, 2017

Explain details The on() Method.

The on() Method

The on() method attaches one or more event handlers for the selected elements.
Attach a click event to a <p> element:

Example

$("p").on("click", function(){
    $(this).hide();
});
Attach multiple event handlers to a <p> element:

Example

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