I am a jQuery beginner and while going through some code examples I found:
$(document.body) and $('body')
$(document.body)
$('body')
Is there any difference between these two?
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.
document.body
'body'
In practice either will get the job done.
If you are interested, there is more information in the documentation for the jQuery function.
2.1m questions
2.1m answers
60 comments
57.0k users