Hi all : quick question : I have three Select elements in my page, which I need to fill with the same options (initially). The data comes from a AJAX request.
Can somebody tell me why only the first Select has the options appended (allthough it is last in the .each()), whereas the others do not? It is not a major problem, I can solve it in other ways, but I was just curious if someone could explain this to me.
$(document).ready(function () {
var data = {test: "testing", test2: "testing2", test3: "testing3"}
let subscriptionSelect = $('#select1');
let showSelect = $('#select3');
let noShowSelect = $('#select4');
subscriptionSelect.empty().append($('<option></option>').val('').text('------'));
showSelect.empty().append($('<option></option>').val('').text('------'));
noShowSelect.empty().append($('<option></option>').val('').text('------'));
$.each(data, function (key, value) {
let option = new Option(key, value);
noShowSelect.append(option);
showSelect.append(option);
subscriptionSelect.append(option);
});
},
);
JSFiddle : https://jsfiddle.net/stuoq3f5/