These two methods are relatively easy to confuse. The
filter method represents filtering the current internal elements. This method accepts two parameters, a function that returns bool, or a JQuery selection expression that wraps the set. The elements of will only be less than or equal to the elements in the current packaging set, and the contained elements belong to a subset of the elements in the original packaging set:
The find method searches within the current element (sub-element) and returns a new packaging set, which means that the packaging set may increase :
As can be seen from the above, the elements in the new packaging set have been added
parents() method VS closest() Method
Both methods search upwards from the current element to match the element. The differences are as follows:
For the parents method, all matching elements upward from the current element will be added to the new packaging set and returned, while the closest method will only include The closest element to the current element, so after using the closest method, the elements in the current packaging set can only be 1 or 0
. The parents method does not include the elements in the current packaging set, while the closest method will include the elements in the current packaging set. Element
direct child elements VS all child elements
Use children to return direct child elements, and use find plus wildcards to return all child elements except text nodes:
text node here
< ;div id="two">
the two
It can be seen that the children method will only contain the direct child elements of the current element, and using find(">* will also produce the same effect"). If you want to adopt all the direct child elements, pass it directly within find"* "Wildcard
Go back to the past end() method and andself() method
All the above methods, as well as add(), next(), nextAll(), prev(), etc., perform operations on the elements in the package set Changed methods can use the end() method to return:
The
end() method always offsets the most recent method that changed the wrapper set, and offsets other methods:
text node here
< ;p id="p1">
the two
Change if necessary When wrapping elements in the set, you also need to include the original elements in the wrapping set, using the andself method:
We will find that alert two is first, because two is selected first
PS:liver writer code highlighting plug-in When I added Chinese characters, the characters were garbled, and I was very depressed and said -.-!! So the comments were all in the language of birds.