I have a quick question about jQuery selectors.
Is doing this:
$('.class_el_1, .class_el_2').hide();
The same as just looping through each element using jQuery’s .each function?
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.
It has the same effect of hiding them all, but it’s not exactly the same internally, no.
.each()takes a callback in whichthiscan be used to do specific things to each element, so it does a bit more work..hide()in a chain just setsdisplay: none;on the elements (storing their previous value).You can see how it works internally here, for your call with no parameters:
In the above
thisrefers to the element set that$('.class_el_1, .class_el_2')matched, just using aforloop to literate over them.