Last active
December 22, 2015 21:29
-
-
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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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