JSFiddle - React, Tailwind, and code Playground
by David Thomas
HTML
<select id="select"></select>
JavaScript
function populateWithChildren(parent, childTag, values) {
if (!parent || !values) {
return false;
} else {
values = typeof values === "string" ? values.split(',') : values;
for (var i = 0, len = values.length; i < len; i++) {
var newElem = document.createElement(childTag),
text = document.createTextNode(values[i]);
newElem.appendChild(text);
parent.appendChild(newElem);
}
}
}
var parent = document.getElementById('select'),
x = 'Jenny,John,Stephanie,Marc,Ryan,Jessica';
populateWithChildren(parent, 'option', x);