5
I was wondering if there’s a better way to insert a option
in the select
with jquery.
Example:
<select name="municipio_evento" id="municipio_evento">
<option value=""></option>
<option value="1">ACEGUA</option>
<option value="2">AGUA SANTA</option>
<option value="3">AGUDO</option>
<select>
I know I can do it that way:
$('#municipio_evento').append('<option value="4">AGUAS CLARAS</option>');
If anyone has any suggestions or ideas please.
This way works well. More interesting would be to know how you plan to use this code. Only there can we tell if there is a better way. But I don’t see the problem.
– Sergio
The way I want to use is dynamic, meaning that only one or several options can come. The fact is that inserting a string of this size does not seem to be the best way.
– Diego Filipe Pedro Santos
jQuery looks like this. Mootools in this respect is more "Javascript" using
createElement
and joining properties. If you will use jQuery this way works. Maybe it is good to create a function that givesreturn '<option value="'+valor+'">'+nome+'</option>'
. If you want a concrete example you have to put more code for the example to be more accurate.– Sergio