Skip to content

Instantly share code, notes, and snippets.

@arufian
Created April 12, 2013 09:11
Show Gist options
  • Save arufian/5370712 to your computer and use it in GitHub Desktop.
Save arufian/5370712 to your computer and use it in GitHub Desktop.
Make a colorful combobox
<select id="test">
<option id="test1">test1</option>
<option id="test2">test2</option>
<option id="test3">test3</option>
<option id="test4">test4</option>
<option id="test5">test5</option>
</select>
var testCombo = document.querySelector('#test');
document.querySelector('#test1').style.color = "red";
document.querySelector('#test2').style.color = "blue";
document.querySelector('#test3').style.color = "yellow";
document.querySelector('#test4').style.color = "gray";
document.querySelector('#test5').style.color = "green";
testCombo.addEventListener('change', function(){
testCombo.style.color = testCombo.options[testCombo.selectedIndex].style.color;
}, false);
testCombo.style.color = testCombo.options[testCombo.selectedIndex].style.color;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment