Why is there a filter function in jQuery when you can get and show / hide the elements by class?
$('.yourClass');
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.
Just because you have some elements that you’d like to work with doesn’t mean that they’re in the DOM. Consider this contrived example:
Demo: http://jsfiddle.net/ambiguous/h3GMB/
The first one,
$('.a'), gives you nothing because$elsaren’t in the DOM yet. The second one also gives you nothing becausefindsearches descendents. Only the third one will give you what you’re looking for becausefilterreduces:This sort of manipulation of things not in the DOM is fairly common when preparing template chunks for the DOM. The difference between
filterandfindis also fairly important even when the elements in question are in the DOM.