personally I prefer the first syntax
jQuery()
is it safe respect to the common used:
$(document).ready()
For the other selector i will anyway use $('#id'). i am just asking for the first .ready
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The two names
$andjQueryare synonyms.jQueryis the more explicit;$may be overridden if you use another framework.If you pass a function as the first argument to your call to the
jQueryfunction (or, obviously, to$), it is executed exactly as if it were a call tojQuery(document).ready. So yes, it is exactly the same.Indeed, all these are functionally equivalent (provided you don’t have anything else mucking around with
$):It is entirely a matter of circumstance and style as to which you use.
My personal preference is to use the explicit
$(document).readycall (#1): it is obvious that this is code that will be run when the DOM is ready. The major advantage of your preference (#4) is that it clearly denotes that the code is jQuery, which may be useful for someone reading your code in future.