Skip to content

Instantly share code, notes, and snippets.

@mojaray2k
Last active December 22, 2015 21:29
Show Gist options
  • Save mojaray2k/6533574 to your computer and use it in GitHub Desktop.
Save mojaray2k/6533574 to your computer and use it in GitHub Desktop.
The jQuery end() method restores your collection to what is was before the last time it was modified (this includes filtering, finding, slicing, and more). Below is an example:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mastering the jQuery End Method</title>
</head>
<body>
<ul id="meals">
<li>
<ul class="breakfast">
<li class="eggs">No</li>
<li class="toast">No</li>
<li class="juice">No</li>
</ul>
</li>
</ul>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
var breakfast = $('#meals .breakfast');
breakfast.find('.eggs').text('Yes').end().find('.toast').text('Yes').end().find('.juice').toggleClass('juice coffee').text('Yes');
breakfast.find('li').each(function() {
console.log(this.className + ': ' + this.textContent);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment