Programmatically create select list

var arr = [
  {val : 1, text: 'One'},
  {val : 2, text: 'Two'},
  {val : 3, text: 'Three'}
];

var sel = $('<select>').appendTo('body');
$(arr).each(function() {
 sel.append($("<option>").attr('value',this.val).text(this.text));
});

Leave a Comment