Home/Jquery/.find() vs .filter()

.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’);

READ  Query append() VS appendTo()

find() :

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

Leave A Comment