jQuery mouseover Event

Beginner
5 min read
Updated: Nov 2026
3 examples
Mouse Events

Definition

The mouseover event fires when the pointer enters an element (bound with .on("mouseover") since jQuery 1.7). It bubbles — entering a child also notifies the parent. Pair historically with mouseout; for nested UI prefer mouseenter / mouseleave.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("#outer").on("mouseover", function (event) { … })

bubbles: parent → fires when entering OR crossing into a child
mouseenter: fires only when entering from outside

event.relatedTarget → element the pointer came from
.trigger("mouseover") → run handlers manually
CallWhat it does
mouseoverLearn the jQuery mouseover event: bind with .on('mouseover'), understand bubbling vs mouseenter, filter with event.relatedTarget, trigger handlers, examples, pitfalls, and FAQs.

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Select the element that should react when the pointer enters.
Step 2Bind with .on("mouseover", handler).
Step 3If children exist, check event.relatedTarget — or switch to mouseenter.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

Example 1 — Bind Handler on #outer

Official pattern: log when the pointer enters the outer element — including into a child.

jQuery
$("#outer").on("mouseover", function () {
  $("#log").append("Handler for mouseover called.\n");
});
Try It Yourself

How It Works

  1. Bind the event. .on("mouseover", fn) registers the handler on #outer.
  2. Enter the element. Arriving from outside runs the function.
  3. Cross into a child. Moving Outer → Inner also fires because of bubbling.

Example 2 — Trigger from Another Element

Click a button to fire the same handler with .trigger("mouseover").

jQuery
$("#outer").on("mouseover", function () {
  $("#log").append("Handler for mouseover called.\n");
});

$("#other").on("click", function () {
  $("#outer").trigger("mouseover");
});
Try It Yourself

How It Works

  1. Same handler. Real enters and triggers both call the bound function.
  2. Synthetic event. .trigger("mouseover") runs handlers without a real pointer move.
  3. Bubbling still applies. Use .triggerHandler("mouseover") to avoid bubble side effects.

Example 3 — mouseover vs mouseenter

Official comparison: count enter events on nested boxes — adapted from the jQuery API demo.

jQuery
var i = 0;
$(".overout").on("mouseover", function () {
  $("span", this).text("mouse over x " + (++i));
});

var n = 0;
$(".enterleave").on("mouseenter", function () {
  $("span", this).text("mouse enter x " + (++n));
});
Try It Yourself

How It Works

  1. Left box uses mouseover. Every child boundary can increment the counter.
  2. Right box uses mouseenter. Only a true entry from outside increments.
  3. Same nesting. The HTML shape is identical — only the event differs.

Frequently Asked Questions

mouseover fires when the pointer enters an element. Bind with .on('mouseover', handler) (since jQuery 1.7). Unlike mouseenter, it bubbles — it also fires when moving from a parent into a child inside the bound element.
When the pointer enters a child, mouseover bubbles to ancestors. A handler on an outer menu can fire again even though the user is already inside. Prefer mouseenter for nested menus, or filter with event.relatedTarget.
relatedTarget is the element the pointer came from. If it is still inside the bound element, you can ignore the event: if ($(event.relatedTarget).closest('#outer').length) return;
mouseover bubbles and re-fires on child boundary crossings. mouseenter fires only when the pointer enters the bound element from outside. For hover menus and tooltips with nested content, prefer mouseenter with mouseleave.
Call .trigger('mouseover') on the element. Use .triggerHandler('mouseover') to run handlers without bubbling.
Use .on('mouseover', handler). The .mouseover() shorthand is deprecated since jQuery 3.3. Unbind with .off('mouseover').

Next: .mouseover() Method — Deprecated Shorthand

See the deprecated shorthand and how it maps to .on("mouseover").

.mouseover() Method — Deprecated Shorthand tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful