Handling the Mouse Entering or Leaving Elements

$("p").on("mouseover", function (e){   $(this).html("Hello mouse."); }); $("p").on("mouseout", function (e){   $(this).html("Wait, don't go."); });

The browser provides an event each time the mouse enters or leaves an element. The standard JavaScript events are mouseover and mouseout, so you can use .on("mouseover") to add an event handler for the mouse entering an element and .on("mouseout") to add an event handler for when the mouse leaves.

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.