Does jQuery always return array when selecting element (of course if at least one element exists)? Example:
$('#Myelement')
$('div')
$('tbody')
What if the selector is an ID?
What if the selector is an element but has only one occurrence?
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 jQuery function always returns a jQuery object (that is based on an array), even if there are no elements that matches the selector.
That way you can always call a method that is supposed to affect the elements found, even if there are no elements that matched. If the jQuery object contains no elements, it will simply do nothing.
If you need to know if a jQuery object contains any elements, you can use the
lengthproperty.