How do I add options to a DropDownList using jQuery

0 votes
As the question says, how do I add a new option to a DropDownList using jQuery?

Thanks
Jun 21, 2022 in JQuery by gaurav
• 23,260 points
503 views

1 answer to this question.

0 votes

Without using any extra plugins,

var myOptions = {
    val1 : 'text1',
    val2 : 'text2'
};
var mySelect = $('#mySelect');
$.each(myOptions, function(val, text) {
    mySelect.append(
        $('<option></option>').val(val).html(text)
    );
});
answered Jun 21, 2022 by rajatha
• 7,680 points

Related Questions In JQuery

0 votes
1 answer

How do I iterate through children elements of a div using jQuery?

Hello @kartik, Use children() and each(), you can optionally pass a ...READ MORE

answered Oct 5, 2020 in JQuery by Niroj
• 82,840 points
5,516 views
0 votes
1 answer

How do I select a sibling element using jQuery?

Use jQuery . siblings() to select the matching ...READ MORE

answered Jun 6, 2022 in JQuery by Edureka
• 13,690 points
479 views
0 votes
1 answer

How do I select a sibling element using jQuery?

jQuery siblings() Method The siblings() method returns all ...READ MORE

answered Jun 7, 2022 in JQuery by Edureka
• 13,690 points
2,428 views
0 votes
1 answer

How do I pre-populate a jQuery Datepicker textbox with today's date?

Hello @kartik, You must FIRST call datepicker() > then use ...READ MORE

answered May 29, 2020 in JQuery by Niroj
• 82,840 points
12,202 views
0 votes
1 answer
0 votes
1 answer

How do I set variable if a specific package version is installed in CFEngine?

Here is what you can do.Just use packagesmatching to ...READ MORE

answered Jul 12, 2018 in Other DevOps Questions by Atul
• 10,240 points
1,180 views
0 votes
1 answer

How to open a Bootstrap 4 modal dialog using jQuery

Use the modal('show') Method You can simply use ...READ MORE

answered Jun 28, 2022 in JQuery by rajatha
• 7,680 points
7,190 views
0 votes
1 answer

How to trigger a click on a link using jQuery

$( "#foo" ). trigger( "click" ); As of jQuery ...READ MORE

answered Jun 10, 2022 in JQuery by rajatha
• 7,680 points
726 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP