Difference between $(document.body) and $('body')

前端 未结 6 1564
傲寒
傲寒 2020-12-13 11:48

I am a jQuery beginner and while going through some code examples I found:

$(document.body) and $(\'body\')

Is there any difference

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 12:19

    $(document.body) is using the global reference document to get a reference to the body, whereas $('body') is a selector in which jQuery will get the reference to the element on the document.

    No major difference that I can see, not any noticeable performance gain from one to the other.

提交回复
热议问题