jQuery event handling - bind to document or 'body' element?

后端 未结 5 946
长发绾君心
长发绾君心 2020-12-31 01:36

I have noticed the use of $(document) and $(\'body\') when we want to reference the entire page, especially when binding events.

$(         


        
5条回答
  •  醉酒成梦
    2020-12-31 01:58

    $('body') targets the html element, while $(document) targets the entire html document. That means if you want to reference something in the element you'll want to get there from $(document) because that's a direct path.

    For your purposes, based on what you've shown us, they should be equivalent.

提交回复
热议问题