Skip to content

Instantly share code, notes, and snippets.

@doochik
Created December 28, 2017 19:42
Show Gist options
  • Save doochik/542e64da671e6876f2f6d3826df9a237 to your computer and use it in GitHub Desktop.
Save doochik/542e64da671e6876f2f6d3826df9a237 to your computer and use it in GitHub Desktop.
// data array
var foo = [{title: ‘1’, value: ‘1’ }, {title: ‘2’, value: ‘2’ }]
// html for new select
var html= [
'<select>',
foo.map(function(item){ return '<option value="' + item.value + '">' + item.title + '</option>' }),
'</select>'
].join('');
// find old select container in DOM
var oldSelectContainer = document.getElementById('select-container');
// replace content with new select
oldSelectContainer.innerHTML = html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment