zod zod - 3 months ago 19
jQuery Question

$("#select option:second").val() jquery - keep select second value of select box option

I am able to keep select the first and last value of a select box

$("#selbox").val($("#sel_selbox option:last").val());

$("#selbox").val($("#selbox option:last").val());


How can i keep select the second value ?

$("#selbox").val($("#selbox option:second").val());


THis is giving error. Is there any option to keep select by giving index ?

Answer

Yes, you want the special jQuery eq() selector.

    $("#selbox").val($("#selbox option:eq(1)").val());