Code has been added to clipboard!

jQuery .mouseenter(): Attach Event Handlers to mouseenter Event

Reading time 1 min
Published Jan 9, 2018
Updated Oct 10, 2019

jQuery mouseenter: Main Tips

  • The jQuery .mouseenter() adds an event handler, running a function when the mouseenter event occurs, or triggers the event handler.
  • The mouseenter event happens once a mouse pointer enters elements.
  • Unlike an otherwise similar .mouseover() method, .mouseenter() doesn't react to event bubbling.

Usage of Syntax of .mouseenter()

The .mouseenter() method in jQuery attaches an event handler, invoking a function when the mouseenter event occurs. The function can also trigger the handler for said event.

In the example below, a paragraph of text changes background color to red when a jQuery mouse enter event is detected:

Example
$("div").mouseenter(() => {
    $("div").css("background-color", "red");
});

Follow this syntax to trigger the mouseenter event handler:

$("selector").mouseenter();

Attach the event handler by using this syntax:

$("selector").mouseenter(function);

Event Bubbling with .mouseenter()

In the example below, you can see the difference between jQuery .mouseenter() and .mouseover() methods:

Example
var i = 0;
$( "div.overout" )
  .mouseover(function() {
    $( "p:first", this ).text( "mouse over" );
    $( "p:last", this ).text( ++i );
  })
  .mouseout(function() {
    $( "p:first", this ).text( "mouse out" );
  });
 
var n = 0;
$( "div.enterleave" )
  .mouseenter(function() {
    $( "p:first", this ).text( "mouse enter" );
    $( "p:last", this ).text( ++n );
  })
  .mouseleave(function() {
    $( "p:first", this ).text( "mouse leave" );
  });

As you can see, unlike .mouseover(), .mouseenter() does not support event bubbling. This means the event only triggers its handler when the cursor enters the element it is applied to, not caring about its parents or children.

Learn jQuery
Introduction
Selectors
Events
Event Methods
Download
Callback
Chaining
Get and Set
Add Element
Remove Element
Traverse
Parent
Children
Sibling Traverse
Filtering
jQuery AJAX
Effects
Show and Hide
Fade Effect
Slide Effect
Animate Effect
Manipulate CSS
Width and Height
.addClass()
.after()
.animate()
.append()
.appendTo()
.attr()
.before()
.bind() (deprecated)
.blur()
.change()
.click()
.clone()
.css()
.dblclick()
.delay()
.delegate() and .undelegate() (deprecated)
.detach()
.empty()
.end()
.error() (deprecated)
.fadeIn()
.fadeOut()
.fadeTo()
.fadeToggle()
.finish()
.focus()
.focusIn()
.focusOut()
.hasClass()
.height()
.hide()
.hover()
.html()
.innerHeight()
.innerWidth()
.insertAfter()
.insertBefore()
.keypress()
.keyup()
.live() and .die() (deprecated)
.load() (deprecated)
.mousedown()
.mouseenter()
.mouseleave()
.mousemove()
.mouseout()
.mouseover()
.mouseup()
.off()
.offset()
.offsetParent()
.on()
.one()
.outerHeight()
.outerWidth()
.position()
.prepend()
.prependTo()
.prop()
.proxy()
.queue()
.ready()
.remove()
.removeAttr()
.removeClass()
.removeProp()
.replaceAll()
.replaceWith()
.resize()
.scroll()
.scrollLeft()
.scrollTop()
.show()
.slideDown()
.slideToggle()
.slideUp()
.stop()
.submit()
.text()
.toggle()
.toggleClass()
.trigger()
.triggerHandler()
.unbind() (deprecated)
.unload() (deprecated)
.unwrap()
.val()
.width()
.wrap()
Event Properties
event.currentTarget
event.preventDefault()
event.relatedTarget
event.stopImmediatePropagation()
event.stopPropagation()
event.target
event.timeStamp
event.type
event.which
jQuery .find()
jQuery .keydown()
jQuery.noConflict()
pageY and pageX