onwheel
A wheel or equivalent input device produces a scroll or zoom gesture. 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: WheelEvent. For the described native event: bubbles: yes; cancelable: varies. Inspect deltaX, deltaY and deltaMode; wheel is not equivalent to scroll. Passive listeners cannot prevent defaults. Example: Scroll the region with keyboard, wheel or touch as applicable. 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
<div onwheel="handleEvent(event)"> target.addEventListener("wheel", event => { /* handle event */ });Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| onwheel | JavaScript handler body | Optional HTML event-handler code; the example uses a registered listener instead. Not a Boolean attribute. |
| event | WheelEvent | Event object delivered to the addEventListener callback; event.type is "wheel". Inspect target, currentTarget, bubbles and cancelable as appropriate. |
Working Example
<div id="demo" tabindex="0" aria-label="Scrollable example" style="height:100px;overflow:auto;border:1px solid"> <div style="height:400px">Scroll this region</div></div><p role="status" id="log">Waiting for wheel</p><script> const target = document.getElementById("demo"); const log = document.getElementById("log"); target.addEventListener("wheel", event => { log.textContent = String(event.deltaY); });</script>