tags:

views:

21

answers:

2

Any other way of writing this?

$("#list option:eq(24), #list option:eq(10),
 #list option:eq(26)")
.attr("selected", "selected");
+1  A: 

Try this:

$("#list option").filter(function (index) {
    return index == 10 || index == 24 || index == 26;
}).attr("selected", "selected");

Or this:

$("#list option").filter(":eq(10), :eq(24), :eq(26)")
    .attr("selected", "selected");

Untested, so handle with care.

MrMage
That's "easier"?
cletus
"Easier" was not asked for. But this method might be faster due to a smaller query expression.
MrMage
A: 

Maybe:

$("#list option").filter(function(val, i) {
    return [10,24,26].indexOf(i) + 1;
}).attr("selected", "selected");
Gumbo