4
I’m trying to create a select
which receives its options via Javascript or jQuery, the data is stored in an array.
Example:
for (i = 0; i <= cidades.length; i++) {
$('select').append('<option>' + cidades[i] + '</option>');
}
But they do not appear. the append()
does not work in this case ?
The only thing wrong with your code is that i has to be smaller (<) than cities.length and not smaller or equal (<=). But that wouldn’t stop you from adding the options to your select. Make sure you really have data added to the array, if there really is a select on the page, and if the jQuery library actually loaded it. I also suggest to check if the browser console (F12) shows any error, and if yes copy and add in your question.
– Joao Paulo