-1

I want to disable select options when if div text matces to one of the options class name, here is my code:

<select>
    <option class="aaa" value="aaa">aaa</option>
    <option class="bbb" value="bbb">bbb</option>
    <option class="ccc" value="ccc">ccc</option>
    <option class="ddd" value="ddd">ddd</option>
</select>

<div class="field">
    <div>aaa</div>
    <div>ccc</div>
</div>

in this example aaa and ccc options shoud be disabled, Thanks!

test
  • 2,429
  • 15
  • 44
  • 81

2 Answers2

1
$('select option').prop('disabled',false); // reset
$('.field > *').each(function() {
    var str = $(this).text();
    $('select option.'+str).prop('disabled',true);
});

http://jsfiddle.net/mblase75/y7Cv4/

Blazemonger
  • 90,923
  • 26
  • 142
  • 180
0

JSFIDDLE DEMO

$('div').not('.field').each(function () {
    var txt = $(this).text();
    $('option[value=' + txt + ']').prop('disabled',true);
});
Venkata Krishna
  • 14,926
  • 5
  • 42
  • 56