Using JQuery:
Sometimes, I can do variable.val() and it works. Sometimes, I’m required to use $(variable).val().
I want to be able to make the choice without trial-and-error.
Does anyone know when to wrap an object with $() while using JQuery?
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.
Wrapping a DOM object with $() will convert it to a jQuery Wrapped Set Element. This way you should be able to call jQuery methods with it (val(), attr(), show(), hide(), serialize()).
If however you need to get or set pure javascript properties, then you shouldn’t wrap it.