Knowledge Walls
John Peter
Pune, Maharashtra, India
How to select first few elements in jquery selector with Example
1344 Views
$.slice(startIndex,endIndex) 
slice method is used to select from startIndex to endIndex of selected list of elements by selector in jquery. slice method of jquery is used to select first few elements in jquery elements.

$(element).slice(0,3).css("color","red");
Example: HTML
<div class="my_div">A</div>
<div class="my_div">B</div>
<div class="my_div">C</div>
<div class="my_div">D</div>
<div class="my_div">E</div>
JQuery
$(function(){
   $(".my_div").slice(0,3).css("color","red");
});
Demo & Output 
Best Lessons of "One day One Thing to Know"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details