I'm trying to add a class to select option value based on array values received from ajax call.
HTML
<select id="my_id">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
JAVASCRIPT
//array received from ajax call
var array = [1,3,5]
// loop through dropdown options
$("#my_id > option").each(function(i) {
// if option value in array, add class
if ( array.indexOf(i.value) != -1 ) {
// set matching values to red color
$(this).addClass("red");
}
});