Home > Web Front-end > JS Tutorial > body text

Usage of end method in jQuery

巴扎黑
Release: 2017-06-24 11:14:51
Original
2302 people have browsed it

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($(&#39;p&#39;).filter(&#39;.middle&#39;).length); // alerts 1
	alert($(&#39;p&#39;).filter(&#39;.middle&#39;).end().length); // alerts 3
	alert($(&#39;p&#39;).filter(&#39;.middle&#39;).find(&#39;span&#39;).end().end().length); // alerts 3
</script>
</body>
</html>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template