Reputation: 3359
I've spent some time trying to find an elegant and cross browser solution but was unable. I'm trying to dynamically create a drop down. Here is my html:
...
<span id="currencies">
</span>
...
In my script I'm trying to do the following:
I am assuming that for the code to be cross browser it should be written using jQuery. When I say elegant I mean possibly trying to avoid too much markup, for example, something like this:
// THIS IS NOT A WORKING CODE
$('#currencies').appendSelect().addOption('AAA', 'AAA').addOption('BBB', 'BBB')...
Maybe somebody has some tip. Thank you.
Upvotes: 2
Views: 93
Reputation: 30135
I would probably do it like this:
var $s = $('<select/>').appendTo($('#currencies'));
$.each(['AAA','BBB','CCC','DDD'],function(i,text){
$s.append($('<option/>',{value:text,html:text}));
});
Upvotes: 1
Reputation: 98
You must make A string
var string1='<option>AAA</option><option>BBB</option>.........</option>'
Then
$('#currencies').html(string1);
will do the Job for You
Upvotes: 0