Skip to content
Fix Code Error

Adding options to a using jQuery?

March 13, 2021 by Code Error
Posted By: Anonymous

What’s the easiest way to add an option to a dropdown using jQuery?

Will this work?

$("#mySelect").append('<option value=1>My option</option>');

Solution

This did NOT work in IE8 (yet did in FF):

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

This DID work:

var o = new Option("option text", "value");
/// jquerify the DOM object 'o' so we can use the html method
$(o).html("option text");
$("#selectList").append(o);
Answered By: Anonymous

Related Articles

  • How to implement a Navbar Dropdown Hover in Bootstrap v4?
  • Trying to keep dropdown menus flush to the edge of…
  • Bootstrap 4: Multilevel Dropdown Inside Navigation
  • Hide one dropdown in side menu when another opens
  • I'm working on pagination for my project. How do I…
  • Polymer paper-dropdown-menu not rendered correctly…
  • Polymer - How to data-bind paper-dropdown menu…
  • Select Tag Helper in ASP.NET Core MVC
  • getting text input from a form in react.js using Refs
  • Bootstrap-vue: how can I display the text of a…
  • How do I enable dropdown on hover in vue bootstrap?
  • Bootstrap dropdown sub menu missing
  • in responsive menu it puts two links on the same line
  • How to set `border-radius` of `paper-listbox` inside…
  • How do you remove all the options of a select box…
  • bootstrap-vue multi level drop down
  • How can I handle paper-dropdown-close event in my…
  • Polymer 1.0 Trying to make a splitter which works…
  • Navbar not filling width of page when reduced to mobile view
  • Typeerror: n is undefined in underscore.min.js
  • Apache server keeps crashing, "caught SIGTERM,…
  • How to get data value from bookstrap dropdown-menu…
  • Align nav-items to right side in bootstrap-4
  • After a little scroll, the sticky navbar just is not…
  • Unable to Click on Dropdown using Python Selenium
  • Polymer 1.0 dynamically add options to menu
  • ASP.NET MVC Dropdown List From SelectList
  • Polymer 1.x: Two-way databinding for paper-dropdown-menu
  • Avoid dropdown menu close on click inside
  • CRUD - Create select dropdown list autofills another…
  • Change text colour with bootstrap-vue navbar item-dropdown
  • How to use Bootstrap-Vue with a custom navbar…
  • Vue.js - Element UI - Nested dialog won't open from…
  • How to make Twitter Bootstrap menu dropdown on hover…
  • Svelte and Jquery - Dropdown.svelte:7 Uncaught…
  • Increase bootstrap dropdown menu width
  • Issue when trying to toggle the dropdown sub menu in Vuejs?
  • react-table has a issue with rendering in next.js
  • Use cases for vue.js directive vs component?
  • Dropdown menu cutting off
  • Twitter Bootstrap inline input with dropdown
  • How get clicked item in vue
  • Does Ember.js support IE6?
  • How do I put the selected core-menu item into a…
  • Bootstrap: Position of dropdown menu relative to navbar item
  • Add a Polymer paper-dropdown-menu to a page from javascript?
  • Polymer example not working on Firefox
  • Twitter Bootstrap dropdown menu
  • vue.js 2.0 communication best practice
  • Can't fire iron-select event on paper-listbox
  • Create a Dropdown List for MVC3 using Entity…
  • Scrollable Menu with Bootstrap - Menu expanding its…
  • paper-item - way to place value for paper-dropdown?
  • How to style Polymer dropdown menu arrow
  • There is no ViewData item of type 'IEnumerable' that…
  • setTimeout function not working : javascript
  • Rendering custom styles in bootstrap-vue
  • Inserting images inside the bootstrap-vue select options
  • MVC - Set selected value of SelectList
  • Html.DropdownListFor selected value not being set
  • Vue.js: Default data in component is always…
  • Aurelia is emitting different css code in Foundation…
  • Get BootstrapVue Dropdown (b-dropdown) to show when…
  • Bootstrap-vue issue with b-nav-item, can't change color
  • Create a Bootstrap select with options on an icon span
  • Change text color of a dropdown menu in bootstrap-vue
  • Polymer dropdown data binding with AJAX response
  • Vuejs on blur for custom select element not working
  • jquery remove "selected" attribute of option?
  • How do I add options to a DropDownList using jQuery?
  • paper-dropdown-menu default selected option doesn't work
  • EmberJS trigger action on parent component from child
  • How to close dropdown on outside click NEXT.JS
  • Difference between variable declaration syntaxes in…
  • ngModel Binding on Polymer dropdown (Angular2)
  • Unable to open debugger port in IntelliJ
  • Trying to render dynamic dropdowns using Bootstrap…
  • Trouble with a Semantic UI/jQuery dropdown button…
  • Polymer Dom-Repeat Binding to Content
  • How to subscribe to Polymer paper-dropdown-menu…
  • "Thinking in AngularJS" if I have a jQuery background?
  • IE8 issue with Twitter Bootstrap 3
  • Error while trying to rename downloaded pdf file in…
  • How to add Drop-Down list () programmatically?
  • VueJs Router doesn't render componenet
  • How can you manually toggle a Foundation 5 dropdown…
  • Autosize the paper-dropdown-menu width
  • For-each over an array in JavaScript
  • Backbone.Marionette Layout + Region + View inserts…
  • Vue.js - Select / dropdown selected item vm binding…
  • Polymer: apply style to an element under Shadow DOM
  • How to populate polymer-dropdown-menu on click of a button?
  • paper-dropdown-menu selected text style
  • Prevent menu close on multi select…
  • How do you parse and process HTML/XML in PHP?
  • How to use Servlets and Ajax?
  • paper-dropdown-menu options are horizontally stacked…
  • Polymer paper-dialog: how can I know when an…
  • Not submit any value if checkbox is empty
  • Making CORS request using Backbone in IE8/9

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Call a function from another file?

Next Post:

How can I print variable and string on same line in Python?

Leave a Reply Cancel reply

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

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error