Home  >  jQuery

Example of .andSelf() in jQuery

February 20, 2013
.andSelf() is called on any defined element of html. If there are elements in the stack for any purpose, then .andSelf() add the self element in the current stack as
$('li.test').nextAll().andSelf().css('background-color', 'red');
Once all the element are in stack then we can process any css property like background-color etc. Below is the complete example where we process li element.
<!DOCTYPE html>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<li class="test">B</li>
<li >D</li>

.css('background-color', 'green');


Output will look like
  • A
  • B
  • C
  • D

©2022 concretepage.com | Privacy Policy | Contact Us