Question on $(document).bind()
I have a page o开发者_运维技巧n iPad. How do I get the specific element that was touched instead of the generic container element?
$(document).bind("touchstart",function(e){
console.log("touchstart on target : " + e.target.id);
}
Try using delegate
instead
$(function() {
$(document).delegate('div', 'click', function(event) {
alert($(this).attr('id'));
// To prevent Propagation
event.stopPropagation()
});
});
in action: http://jsfiddle.net/xem65/
(Using click since I don't have any touch devices nearby atm)
Docs on delegate: http://api.jquery.com/delegate/
That seems like it should be working. Here is a small test case that logs out the event based off of http://gregmurray.org/ipad/touch-events.html, and it seems to recognize the touchstart happening on the div. Maybe you could post an example where it is failing?
精彩评论