Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - $.each find if first run of $.each

Tags:

jquery

each

I am not sure if I can do this or not: I need to know how to find out if the json $.each is running for the first time.

So say I have 14 items in the JSON the $.each goes though 14 times I want to do something different to the first time the $.each run.

For example, say the first return is the letter A, and in the array we have A,B,C,D,E,F.

I want to bold the A but none of the others.

like image 744
RussellHarrower Avatar asked May 22 '11 07:05

RussellHarrower


1 Answers

The callback function for $.each gets the index as its first parameter:

$.each(collection, function(index, value) {
    // index will be zero on the first one
});
like image 124
mu is too short Avatar answered Nov 15 '22 21:11

mu is too short