W3cubDocs

/DOM

Touch.target

Returns the Element (EventTarget) on which the touch contact started when it was first placed on the surface, even if the touch point has since moved outside the interactive area of that element or even been removed from the document. Note that if the target element is removed from the document, events will still be targeted at it, and hence won't necessarily bubble up to the window or document anymore. If there is any risk of an element being removed while it is being touched, the best practice is to attach the touch listeners directly to the target.

Syntax

var el = touchPoint.target;

Return value

el
The target element of the Touch object.

Example

This example illustrates how to access the Touch object's Touch.target property. The Touch.target property is an Element (EventTarget) on which a touch point is started when contact is first placed on the surface.

In following simple code snippet, we assume the user initiates one or more touch contacts on the source element. When the touchstart event handler for this element is invoked, each touch point's Touch.target property is accessed via the event's TouchEvent.targetTouches list.

// Register a touchmove listener for the 'source' element
var src = document.getElementById("source");

src.addEventListener('touchstart', function(e) {
  // Iterate through the touch points that were activiated 
  // for this element.
  for (var i=0; i < e.targetTouches.length; i++) {
    console.log("touchpoint[" + i + "].target = " + e.targetTouches[i].target);
  }
}, false);

Specifications

Specification Status Comment
Touch Events – Level 2 Editor's Draft Non-stable version.
Touch Events Recommendation Initial definition.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 22.0 (Yes) 18.0 (18.0)[1]
52.0 (52.0)[2]
No support No support No support
Feature Android Android Webview Chrome for Android Edge Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) 6.0 (6.0) (Yes) 11 (Yes) (Yes)

[1] Touch events were implemented in Gecko 18.0, but removed again in 24.0 (Firefox 24.0 / Thunderbird 24.0 / SeaMonkey 2.21) on the desktop version of Firefox due to web compatibility issues (bug 888304).

[2] As of Gecko 52.0, touch events support has been fixed and reenabled in Windows desktop platforms.

© 2005–2017 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/Touch/target