Reputation: 1162
Good day to you all
I am retrieving the options for my select tag in json format and populating the select tag using this
var mySelect = $('#'+select_id)
$.each(response, function(key,val){
$('<option/>',{
value : key
})
.text(val)
.appendTo(mySelect);
});
Which works fine, but i want to store the html string generated out of the conversion from the json array into a variable, instead of appending it to the select tag. How can i do that?
Upvotes: 1
Views: 792
Reputation: 10349
You can accomplish this with jQuery.map
. http://api.jquery.com/jQuery.map/
var result = $.map(response, function(key,val){
return "<option value='" + key + "'>" + val + "</option>";
}).join('');
Upvotes: 1