开发者

Question on $(document).bind()

开发者 https://www.devze.com 2023-03-27 05:28 出处:网络
I have a page o开发者_运维技巧n iPad. How do I get the specific element that was touched instead of the generic container element?

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消