select option add dynamically

var select = $(‘#myselect’);
var newOptions = {
‘red’ : ‘Red’,
‘blue’ : ‘Blue’,
‘green’ : ‘Green’,
‘yellow’ : ‘Yellow’
};
$(‘option’, select).remove();
$.each(newOptions, function(text, key) {
var option = new Option(key, text);
select.append($(option));
});

Leave a Reply

Your email address will not be published. Required fields are marked *