article

Sunday, November 23, 2014

Jquery .first() and .last() Function Examples

Jquery .first() and .last() Function Examples
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  <script>
   $(document).ready(function() { 
 
 $("#first").click(function(){       
  $("li").first().css("background-color",'#DD4B39');      
 });
 
 $("#last").click(function(){         
  $("li").last().css("background-color",'#DD4B39');
 });
 
   });
  </script>
   <div>
  <ul>
   <li>First Element</li>
   <li>Second Element</li>
   <li>Third Element</li>
   <li>Forth Element</li>
   <li>.....</li>  
   <li>.....</li>
   <li>Last Element</li>
  </ul>
 </div>
 </div>
  <button id="first" class="btn">First</button>  
  <button id="last" class="btn">Last</button>  

Related Post