Browse - Programming Tips - Copy options from one select to another

Date: 2019sep16
Language: javaScript
Libary: jQuery

Q.  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')); }