jquery append option to select and set selected code example

Example 1: jquery add option to select

//add option to select with jQuery
$('#selectID').append($('<option>', {
    value: 1,
    text: 'Option Text'
}));

Example 2: set select option as selected jquery

$(document).ready(function() {
    $("#gate option[value='Gateway 2']").prop('selected', true);
    // you need to specify id of combo to set right combo, if more than one combo
});

Example 3: jquery add items to select input

$("#selectList").append(new Option("option text", "value"));

Example 4: add option to select jquery

$.each(items, function (i, item) {
    $('#mySelect').append($('<option>', { 
        value: item.value,
        text : item.text 
    }));
});

Example 5: how to append values to dropdown using jquery

BY LOVE

 $.each(obj , function (key, value) {
                                $('#GroupName').append($('<option>',
                                    {
                                    value: value.id,
                                    text: value.Group_Name
                                }));

Example 6: To append dropdown option using jquery

$('#ddlGroup').append(new Option('Select group', '0'));