.find() vs .filter()

Both filter() and find() methods are very similar, except the former is applies to all the elements, while latter searches child elements only.

find() searches the descendants of the elements in the matched set. filter() searches only the elements in the matched set.

To simple

 1.filter() – search through all the elements.
 2.find() – search through all the child elements only.

filter() :

$(‘div’).filter(‘#div1’).css(‘background’,’red’);

find() :

$(‘div’).find(‘#div1’).css(‘background’,’red’);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.