-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!

3
  • You forgot to post the JavaScript you tried. Commented Jan 16, 2014 at 17:06
  • possible duplicate - assuming he's using javascript. stackoverflow.com/questions/2867362/… Commented Jan 16, 2014 at 17:07
  • @ntgCleaner sadly those solutions use .attr(), which is no longer the correct approach, instead of .prop(). Commented Aug 28, 2014 at 11:57

2 Answers 2

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/

Sign up to request clarification or add additional context in comments.

Comments

0

JSFIDDLE DEMO

$('div').not('.field').each(function () { var txt = $(this).text(); $('option[value=' + txt + ']').prop('disabled',true); }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.