Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

onmouseover — handling pointer entry

The onmouseover attribute contains JavaScript that handles the mouseover event. It can react when the pointer enters an element, but it does not replace keyboard support and can also handle events originating from descendants.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

onmouseover="JavaScript statements"

onmouseover is a global HTML attribute that handles the mouseover event. Its value is a JavaScript function body, not a URL or an event name. The code runs when the corresponding event is delivered; adding the attribute does not itself run it.

Inside an attribute handler, this refers to the element handling the event, and event provides the event object. The attribute contains code text; the JavaScript property element.onmouseover accepts a function or null.

mouseover bubbles, so a handler on an ancestor can also react when the pointer enters a descendant. Moving between descendants can cause further invocations. Do not confuse it with mouseenter, which does not bubble.

Do not make essential functionality depend exclusively on hovering. The example adds a separate onfocus response for keyboard use. Content Security Policy can block attribute code; never interpolate untrusted data into it.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>onmouseover demo</title>
<button type="button" onmouseover="this.textContent = 'mouseover received'" onfocus="this.textContent = 'focus received'">Try mouse or keyboard</button>
</html>

Result

Mouse: mouseover received
Keyboard focus: focus received

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources