Are there any drawbacks to listen events on document level in jQuery?

前端 未结 3 839
南旧
南旧 2020-12-06 12:46

To listen events on elements, I think to listen on document level:

$(document).on(\'click\', \'.myclass\', function() {/*do something*/});

3条回答
  •  抹茶落季
    2020-12-06 13:36

    Another advantage of attaching a click handler directly on the element itself, is that Android seems to like that a lot better. When touching an element that has a click handler, the mobile browser will give a slight hint that something has been activated which it doesn't do when the handler is attached to another element.

    It also seems to work a lot more stable.

提交回复
热议问题