Reputation: 19425
I can disable one and one by doing this:
jQuery('#ListBoxA').attr('disabled','true');
But how can I apply this to multiple items? This does not work:
jQuery('#ListBoxA, #ListBoxB, #ListBoxC').attr('disabled','true');
UPDATE
Not much markup to show....
<select id="ListBoxA" size="4" name="countrySelectBox">
<select id="ListBoxB" size="4" name="cityListBox">
<select id="ListBoxC" size="4" name="storeListBox" multiple="multiple">
Upvotes: 6
Views: 6665
Reputation: 964
The problem was with the whitespace
For disabling items:
$("#ListBoxA,#ListBoxB,#ListBoxC").prop("disabled", true);
For enabling items:
$("#ListBoxA,#ListBoxB,#ListBoxC").prop("disabled", false);
Upvotes: 1
Reputation: 3519
jQuery('#ListBoxA,#ListBoxB,#ListBoxC').attr('disabled','disabled');
(Without white spaces).
To enable use jQuery('#ListBoxA,#ListBoxB,#ListBoxC').removeAttr('disabled');
http://docs.jquery.com/Selectors/multiple#selector1selector2selectorN
Upvotes: 11
Reputation: 108537
You could also use attribute filters if the boxes you want to disable share an attribute (in this case any one with 'ListBox' in it's id:
$("select[id*='ListBox']").attr('disabled',true);
Upvotes: 1
Reputation: 25271
For another option, if you give them all a CSS class, you can do:
jQuery('.ListBoxClass').attr('disabled', true);
Upvotes: 1
Reputation: 800
jQuery('select').each(function(){
jQuery(this).attr('disabled','true');
});
Upvotes: 0