PointerEvent.pointerType

The pointerType read-only property of the PointerEvent interface indicates the device type (mouse, pen, or touch) that caused a given pointer event.

Syntax

var pType = pointerEvent.pointerType;

Return value

pType

The event's pointer type. 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.

Example

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

targetElement.addEventListener('pointerdown', function(event) {
  // Call the appropriate pointer type handler
  switch (event.pointerType) {
    case 'mouse':
      process_pointer_mouse(event);
      break;
    case 'pen':
      process_pointer_pen(event);
      break;
    case 'touch':
      process_pointer_touch(event);
      break;
    default:
      console.log(`pointerType ${event.pointerType} is not supported`);
  }
}, false);

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
pointerType
55
12
59
41
11
10
Returns an integer enumeration instead of a string.
42
13
55
55
79
41
42
13
6.0
fractional_coordinates
64
movementX and movementY are not fractional, see Chromium bug 802067.
79
movementX and movementY are not fractional, see Chromium bug 802067.
12-79
Only clientX, clientY, pageX and pageY are fractional.
No
Yes
Only clientX, clientY, pageX and pageY are fractional.
51
movementX and movementY are not fractional, see Chromium bug 802067.
No
64
movementX and movementY are not fractional, see Chromium bug 802067.
64
movementX and movementY are not fractional, see Chromium bug 802067.
No
47
movementX and movementY are not fractional, see Chromium bug 802067.
No
9.0
movementX and movementY are not fractional, see Chromium bug 802067.

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerType