I have div with 6 classes. I want to know if that div has either class one, two , three, or four and set that as the value of the select box. I only want to search for these 4 classes and don’t care about the other classes in the div. I have the following. Is there a better way to write it.
<div class="four whatever something"></div>
<select>
<option>one</option>
<option>two</option>
<option>three</option>
<option>four</option>
</select>
if ($('div').hasClass(one)) {
$('select').val('one')
} else if ($('div').hasClass('two')) {
$('select').val('two')
}
if ($('div').hasClass('three')) {
$('select').val('three')
}
if ($('div').hasClass('four')) {
$('select').val('four')
}
You could try something like that: