The HTML onpointerup event
The HTML onpointerup attribute runs JavaScript when an active pointer is released over the element. It is an inline handler for the pointerup event; in modern code prefer addEventListener('pointerup', …).
Overview
The onpointerup event attribute runs JavaScript when a pointer is released on the element. In JavaScript the event itself is named pointerup — drop the on prefix when you call addEventListener.
It is one of the Pointer Events — a unified input model that covers mouse, touch and pen with a single set of events. The handler receives a PointerEvent whose pointerType tells you the input kind (mouse, touch or pen), along with pressure and tilt for styluses. Pointer events are the recommended modern choice over separate mouse and touch handlers.
You can wire this up with the inline onpointerup HTML attribute, but the modern, recommended approach is element.addEventListener('pointerup', handler) in JavaScript. That keeps behavior out of your markup, lets you attach several handlers to the same event, and makes them easy to remove. The inline attribute is fine for quick demos.
Syntax
<element onpointerup="handler()">…</element>
element.addEventListener('pointerup', handler);
Best practices
- Prefer
element.addEventListener('pointerup', handler)over the inlineonpointerupattribute — it separates behavior from markup and allows multiple handlers. - Prefer pointer events over separate mouse and touch handlers — one set of code covers every input type.
- Check
event.pointerTypewhen you need to treat mouse, touch and pen differently. - Use
setPointerCapture()for drag-style interactions so the element keeps receiving events.
Frequently asked questions
What is the onpointerup event?
pointerup.What is the difference between pointer events and mouse events?
How do I tell mouse, touch and pen apart?
event.pointerType, which is mouse, touch or pen.Should I use the onpointerup attribute or addEventListener?
addEventListener('pointerup', …) in JavaScript. The inline onpointerup attribute works but mixes behavior into the markup and allows only one handler per element.