PointerEvent: isPrimary property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2020.
TheisPrimary read-only property of thePointerEvent interface indicates whether or not the pointer device thatcreated the event is theprimary pointer. It returnstrue if thepointer that caused the event to be fired is the primary one and returnsfalse otherwise.
In a multi-pointer scenario (such as a touch screen that supports more than one touchpoint), this property is used to identify amaster pointer among the set ofactive pointers for each pointer type. Only a primary pointer will producecompatibility mouse events. Authors who desire only single-pointer interactioncan achieve that by ignoring non-primary pointers.
A pointer is considered primary if the pointer represents a mouse device. A pointerrepresenting pen input is considered the primary pen input if itspointerdown event was dispatched when no other active pointers representingpen input existed. A pointer representing touch input is considered the primary touchinput if itspointerdown event was dispatched when no other active pointersrepresenting touch input existed.
When two or more pointer device types are being used concurrently, multiple pointers(one for eachpointerType) are consideredprimary. For example, a touch contact and a mouse cursor moved simultaneously willproduce pointers that are both considered primary. If there are multiple primarypointers, these pointers will all producecompatibility mouse events (seePointer events for more information about pointer, mouse and touchinteraction).
In this article
Value
A boolean,true if the pointer for this event is the primary pointer and returnsfalse otherwise.
Examples
This example illustrates using the value ofisPrimary to call theappropriate processing function.
target.addEventListener("pointerdown", (event) => { if (event.isPrimary) { process_primary_pointer(event); } else { process_secondary_pointer(event); }});Specifications
| Specification |
|---|
| Pointer Events> # dom-pointerevent-isprimary> |