I have never been very clear about the difference between the filter() method and the find() method. Today I finally figured it out after reading the jQuery Cookbook.
filter() filters the DOM element packaging set, which refers to operating the current element set, deleting unmatched elements, and obtaining a new set
$('div').filter('.div1');//Select the div element with the class attribute of div1 in the div tag
find() finds qualified descendants in the context of the currently selected element, and returns the child element
$('div').find('em');//Select the element of the em tag in the div tag
As can be seen from the above, filter() operates on the selected element set to obtain the qualified elements among these elements, while find() obtains the qualified descendant sub-elements of the selected element
.
Finally, introduce an end() method to return the selection before destructive modification
$('div').filter('.div1').end();//What is returned is the selected element before using filter(), that is, $('div ')
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn