I would like to use .each to change the first option of each individual select element. The code below all works. You can see the .each being using to change (highlight) each select elements border when focused. I can't figure out how to get it to work for replacing the first options however.
$(".select").focusout(function() {
$(".select").css({
"border-color": dd_border_color,
"box-shadow": "unset"
});
});
$(".select").each(function(i) {
$(this).focus(function() {
$(this).css({
"border-color": dd_border_color_s,
"box-shadow": dd_box_shadow
});
});
});
$('.select[id*=sub1] option:eq(0)').replaceWith("<option value disabled hidden></option>");
$('.select[id*=sub2] option:eq(0)').replaceWith("<option value disabled hidden></option>");
$('.select[id*=sub3] option:eq(0)').replaceWith("<option value disabled hidden></option>");
$('.select[id*=sub4] option:eq(0)').replaceWith("<option value disabled hidden></option>");
$('.select[id*=sub5] option:eq(0)').replaceWith("<option value disabled hidden></option>");
$('.select[id*=sub6] option:eq(0)').replaceWith("<option value disabled hidden></option>");
$('.select[id*=sub7] option:eq(0)').replaceWith("<option value disabled hidden></option>");
$('.select[id*=sub8] option:eq(0)').replaceWith("<option value disabled hidden></option>");
I tried:
$('.select[id*=sub] option:eq(0)').each(function(i) {
$(this).replaceWith("<option value disabled hidden></option>");
});
And a number of other combinations, using .eq(0) in different places. It either replaced the first option of the first select, or did nothing at all. Once I figured out how to do this correctly, it'll help me tidy up my code across a number pages in some online quizzes I'm making.