Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .each question

Tags:

jquery

each

Is it possible to run a jQuery .each statement a certain amount of times rather then for each of the items being iterated? The JSON being iterated is a last.fm feed, and of course, they ignore the "limit" request often. I would like to bypass this error by only running the .each statement so many times.

like image 444
Kyle Hotchkiss Avatar asked Jan 21 '10 19:01

Kyle Hotchkiss


Video Answer


1 Answers

var limit = 5;

$("somelement").each(function(i, val) {
      if(i > limit) return false;
      // do stuff
});

or

$("somelement:lt(5)").each(function() {
      // do stuff
});
like image 87
kjagiello Avatar answered Nov 11 '22 04:11

kjagiello