W3cubDocs

/DOM

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 compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 55 12 59
59
41
Disabled
Disabled 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.
11
11
10
Returns an integer enumeration instead of a string.
42 No
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support 55 55 12 No
No
41
Disabled
Disabled 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.
42 No 6.0

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerType