What is the use of end() in jQuery?
<ul id="l"><li class="a">A</li><li class="b">B</li></ul>
$('#l')
.find('.a').addClass('first')
.end()
.find('.b').addClass('second');
HTML after the code runs
<ul id="l">
<li class="a first">A</li>
<li class="b second">B</li>
</ul>
See Method Chaining.
Learn more about the similar topics:
| Tutorials |
|---|
| jQuery Selectors |
| jQuery Traversing: Ancestors |
| jQuery Traversing: Descendants |
| jQuery Traversing: Siblings |
| jQuery Traversing: Filtering |
| Exercises & Assignments |
|---|
| Write jQuery code to count the items of a list |
| Write jQuery code to find the total of a table column |
| Write jQuery code to add alternate row colors to a table |