mouseenter runs when the pointer enters an element and mouseleave runs when it leaves. They are useful when you want clear entry and exit behavior without repeated triggers from child elements.
$( selector ).on( "mouseenter", function () {
// Pointer entered.
});
$( selector ).on( "mouseleave", function () {
// Pointer left.
});
$( function () {
$( "#t123" ).on( "mouseenter", function () {
$( "#d1" ).text( "Mouse entered the area" );
});
$( "#t123" ).on( "mouseleave", function () {
$( "#d1" ).text( "Mouse left the area" );
});
});
<textarea id="t123" rows="4" cols="60">
Bring your mouse inside this area and then take it out.
</textarea>
<div id="d1"></div>
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.