Programming Tips - jQuery: Copy options from one select to another

Date: 2019sep16 Language: javaScript Libary: jQuery Q. jQuery: Copy <option>s from one <select> to another A.
function copySelectOptions(src, dest) { var opts = ''; src.find('option').each(function() { opts += $(this)[0].outerHTML; }); dest.html(opts); // Optionally unselect all dest.removeAttr('selected') }; function exampleUse() { copySelectOptions($('#id1'), $('#id2')); }