jQuery中.find()跟.filter()的区别

jQuery中.find()和.filter()的区别

The jQuery .find() method can be used to create a new set of elements based on context

of the current set of DOM elements and their children elements. People often confuse

the use of the .filter() method and .find() method. The easiest way to remember

the difference is to keep in mind that .find() will operate/select the children of the

current set while .filter() will only operate on the current set of elements. In other

words, if you want to change the current wrapper set by using it as a context to further

select the children of the elements selected, use .find(). If you only want to filter the

current wrapped set and get a new subset of the current DOM elements in the set only,

use .filter(). To boil this down even more, find() returns children elements, while

filter() only filters what is in the current wrapper set.