I want to put an if-else statement in jQuery and also increase a var named count.
How to do it?
I want to put many statements inside the if- and else-blocks:
var count= 1;
$('#MultiSelectItemID :selected').each(function(i, selected) {
{{if count==1}}
{
......................
......................
}
{{else}}
{
.................
.................
}
count++;
}
Is this the right syntax?
Not sure where the
{{and}}came from (templates, perhaps?), but I think all you need is a plain-old Javascript if-else:Also, in case you didn’t notice, at the end of this loop, the
countvariable will actually equal the number of elements plus one, not the actual count. You don’t even need to get the count through incrementing a variable, as thelengthproperty of the jQuery object will equal the count.