We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

PointerEvent.pointerType

The pointerType read-only property of the PointerEvent interface indicates the device type that caused the pointer event. The supported values are the following strings:

mouse
The event was generated by a mouse device.
pen
The event was generated by a pen or stylus device.
touch
The event was generated by a touch such as a finger.

If the device type cannot be detected by the browser, the value can be an empty string (""). If the browser supports pointer device types other than those listed above, the value should be vendor prefixed to avoid conflicting names for different types of devices.

Syntax

var pType = pointerEvent.pointerType;

Return value

pType
The event's pointer type, either the string mouse, pen or touch.

Example

This example illustrates using the value of the pointerType to call the appropriate pointer type processing function.

targetElement.addEventListener("pointerdown", function(ev) {
   // Call the appropriate pointer type handler
   switch (ev.pointerType) {
     case "mouse": 
       process_pointer_mouse(ev); 
       break;
     case "pen": 
       process_pointer_pen(ev); 
       break;
     case "touch": 
       process_pointer_touch(ev); 
       break;
     default:
       console.log("pointerType " + ev.pointerType + " is Not suported");
   }
 }, false);

Specifications

Specification Status Comment
Pointer Events
The definition of 'pointerType' in that specification.
Recommendation Initial definition.
Pointer Events – Level 2
The definition of 'pointerType' in that specification.
Working Draft Non-stable version.
CSS Object Model (CSSOM) View Module
The definition of 'MouseEvent' in that specification.
Working Draft Redefines MouseEvent from long to double. This means that a PointerEvent whose pointerType is mouse will be a double.

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support5512

59

411

11

102

42 No
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support555512

No

411

42 No6.0

1. From version 41: this feature is behind the dom.w3c_pointer_events.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

2. Returns an integer enumeration instead of a string.

Document Tags and Contributors

Contributors to this page: lpd-au, jpmedley, chrisdavidmills, abbycar, rolfedh, AFBarstow
Last updated by: lpd-au,