JSFiddle - React, Tailwind, and code Playground
HTML
<button id="button">Click me</button>
<div id="box"></div>
JavaScript
var color = ["#AAAAAA" , "#FF9992", "#BF9232"];
function addOptions(arr, selectId) {
var s = document.getElementById(selectId);
if (!s) {
s = document.createElement("select");
var myDiv = document.getElementById("box");
myDiv.appendChild(s);
s.id = selectId;
}
s.options.length = 0;
for (var i = 0; i < arr.length; i++) {
var option = document.createElement('option');
option.text = arr[i];
option.style.backgroundColor = arr[i];
option.value = arr[i];
s.options[s.options.length] = option;
}
}
document.getElementById("button").onclick = function () {
addOptions(color, "second");
};