besmart besmart - 22 days ago 4x
Javascript Question

Trying to add a blank <option> with jQuery from a dropdown with ajax

I have a JS function which populates a select based on the value of a first select, but i would like to add an empty at the beginning.

this is the function

function createParkFloorMenu(){
$('#idPark').on('change',function(event) {
var parks = $(this).val();

$.get(floorListUrl, {
idPark: parks
}, function(response) {

var select = $('#idPiano');


$.each(response, function(i, v) {



I tried to add

$('option').val('').text('Seleziona Piano').appendTo($('#idPiano'));

with no success because it populates all the dropdown in my form with "Seleziona Piano" options...


$('option') will find the <option> tags in your dom. If you want to create a new option tag - you need to use $('<option>') (like you already have in your code).

You can use:


in your code right after the remove() part.