remove all other parameters using the filter :gt(0) (0) is the index as follows:
$("select[name='aa'] option:gt(0)").remove();
or disable them as follows:
$("select[name='aa'] option:gt(0)").attr("disabled", "disabled");
and select the element with the filter :eq(0) (0) is the index as follows:
$("select[name='aa'] option:eq(0)").attr("selected", "selected");
the opposite can be done using the filter :not :
$("select[name='aa'] :not(option:gt(0))").attr("disabled", "disabled");
or :lt :
$("select[name='aa'] option:lt(1)").attr("disabled", "disabled");
just assign an empty string .attr("disabled", ""); or .attr("selected", ""); to remove the attribute setting.
the violin is here
flip / flop values ββI think you need a second (hidden) choice:
the violin is here
// hide items var src = $("select[name='aa'] option:eq(0)"); var tar = $("select[name='ab']").hide(); tar.append(src.clone()) src.remove(); //reshow items: src = $("select[name='ab'] option:eq(0)"); tar = $("select[name='aa']") tar.prepend(src.clone()) src.remove();
source share