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

前端 未结 6 1565
傲寒
傲寒 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:24

    Outputwise both are equivalent. Though the second expression goes through a top down lookup from the DOM root. You might want to avoid the additional overhead (however minuscule it may be) if you already have document.body object in hand for JQuery to wrap over. See http://api.jquery.com/jQuery/ #Selector Context

提交回复
热议问题