PointerEvent.pointerType

This article needs a technical review. How you can help.

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.

This property is Read only .

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 – Level 2
The definition of 'pointerType' in that specification.
Editor's Draft Non-stable version.
Pointer Events
The definition of 'pointerType' in that specification.
Recommendation Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 55.0 (Yes) [1] 10 42 No support
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support No support 55.0 No support No support 10 42 No support 55.0

[1] Implementation withdrawn. See bug 1166347.

Document Tags and Contributors

 Contributors to this page: jpmedley, rolfedh, AFBarstow
 Last updated by: jpmedley,