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

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

    They refer to the same element, the difference is that when you say document.body you are passing the element directly to jQuery. Alternatively, when you pass the string 'body', the jQuery selector engine has to interpret the string to figure out what element(s) it refers to.

    In practice either will get the job done.

    If you are interested, there is more information in the documentation for the jQuery function.

提交回复
热议问题