.mouseenter() methodThe .mouseenter() method in jQuery is used to run a function when the mouse pointer enters an elements, or trigger the mouseenter event on an element.
When the mouse pointer enters the element, the event mouseenter is fired.
.mouseenter() method Syntax.mouseenter() .mouseenter(handler) .mouseenter(eventData,handler)
| Parameter | Type | Description |
|---|---|---|
handler |
Function | A function to execute when the mouseenter is triggered on the matched element. |
eventData |
Anything | Additional data passed to the event handler. |
.mouseenter(handler) and .mouseenter(eventData,handler) are shortcut for .on( "mouseenter", handler )
.mouseenter() is shortcut for .trigger( "mouseenter" )
mouseenter is relative to mouseleave.mouseenter() method ExampleTrigger the mouseenter event on target:
HTML
<div id="target">target</div> <div id="btn"> Trigger mouseenter event on target </div>
jQuery
$( "#target" ).mouseenter(function() {
console.log( "mouseenter." );
});
$("#btn").click(function(){
$( "#target" ).mouseenter();
}
.mouseenter([eventData,]handler) method ExampleFollowing is a simple example which change the element's background color when the mouse pointer enters or leaves the element.
$("p").mouseenter(function(){
$(this).css("background-color","cyan");
});
.mouseenter() VS .mouseover()The difference between .mouseenter() and .mouseover() is:
mouseover fires when the pointer moves into the child element as well.(the mouse pointer is over the element).mouseenter fires only when the pointer enters the bound element.