Events

onmouseenter

The mouse enters an element's boundary, including its descendants. HTML event-handler content attribute or corresponding event-handler property; the event fires only on relevant targets. The example uses document.getElementById("demo"). Event interface: MouseEvent. For the described native event: bubbles: no; cancelable: no. Unlike mouseover it does not bubble and is useful for hover state without child transitions. Example: Move the mouse across the button or press/release it as appropriate. The event listener is registered with addEventListener(), which avoids inline script handlers and supports multiple listeners. Inline handlers require a CSP that permits them; do not insert untrusted code into handler attributes.

Formal Syntax & Structure

html syntaxhtml
<button onmouseenter="handleEvent(event)">  target.addEventListener("mouseenter", event => { /* handle event */ });

Parameters & Attributes

NameTypeDescription
onmouseenterJavaScript handler bodyOptional HTML event-handler code; the example uses a registered listener instead. Not a Boolean attribute.
eventMouseEventEvent object delivered to the addEventListener callback; event.type is "mouseenter". Inspect target, currentTarget, bubbles and cancelable as appropriate.

Working Example

Example Snippethtml
<button id="demo" type="button">Interact here</button><p role="status" id="log">Waiting for mouseenter</p><script>  const target = document.getElementById("demo");  const log = document.getElementById("log");  target.addEventListener("mouseenter", event => {    log.textContent = String(event.type + ": " + event.button);  });</script>
HTML Reference