When we use find, filter and other methods on the result set, the result set will be changed.
This method of changing the original result set is called destructive jQuery method
jQuery cookbook has the following definition:
A destructive operation is any operation that changes the set of matched jQuery elements, which means any traversing or manipulation method that returns a jQuery object, includingadd() , andSelf(), children(), closes(), filter(), find(), map(),
next(), nextAll(), not(), parent(), parents(), prev(), prevAll(), siblings(), slice(), clone(), appendTo(), prependTo(), insert<a href="http://www.php.cn/java/java-Before.html" target="_blank">Before</a>(), insertAfter(), replaceAll()
.
The specific usage is as follows
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> </head> <body> <p>Text</p> <p class="middle">Middle <span>Text</span></p> <p>Text</p> <script type="text/javascript" src="jquery-1.11.1.js"></script> <script type="text/javascript"> alert($('p').filter('.middle').length); // alerts 1 alert($('p').filter('.middle').end().length); // alerts 3 alert($('p').filter('.middle').find('span').end().end().length); // alerts 3 </script> </body> </html>
When executing filter('.middle')
on the result of $('p')
, only <p class="middle">Middle <span>Text</span></p>
matches the result.
Continue to perform the above operation end()
, then the effect of filter()
will be undone, and the result set will contain three
The above is the detailed content of Usage of end method in jQuery. For more information, please follow other related articles on the PHP Chinese website!