2

I have function touchstart, touchmove & touchend handler like bellow for an container, the container contains number of elements. In the touchmove handler I am drawing line in canvas.

function touchStartHandler(e){
   var elem = e.target;
   console.log($(elem).text());
}
function touchEndHandler(e){
   var elem = e.target;
   console.log($(elem).text());
}
function touchMoveHandler(e){
   //
}

I want to get the element in the touchend. The event's target is the same element that received the touchstart event. Any solution for this to get element in the touchend event?

sureshunivers
  • 1,753
  • 12
  • 27
  • *"The event's target is the same element that received the touchstart event."* Shouldn't it be? What element are you expecting? – T.J. Crowder Oct 04 '13 at 11:17
  • What about creating global variables? Then the assignation on the first `touchstart` will be in the scope of the `touchend`. – Alvaro Oct 04 '13 at 11:26
  • 1
    @T.J.Crowder Thanks for your reply, In container I have number of DIV elements as grid. on touch start i can get the target in the event (div element 1). I am release touch in the div element 5. On the touchend event handler I am getting element 1 as target. But I need to receive element 5. – sureshunivers Oct 04 '13 at 11:37

1 Answers1

1

Try with e.changedTouches.item(0)

function touchEndHandler(e){
   var elem = e.changedTouches.item(0) ;
   console.log($(elem).text());
}

Take a look at this question for more info: Find element finger is on during a touchend event

Community
  • 1
  • 1
maljukan
  • 2,148
  • 2
  • 25
  • 35