How to disable multiple lists at once using jQuery?

I can disable one and one by doing the following:

jQuery('#ListBoxA').attr('disabled','true');

But how can I apply this to multiple elements? This does not work:

jQuery('#ListBoxA, #ListBoxB, #ListBoxC').attr('disabled','true');

UPDATE

Not a lot of 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">
+3
source share
4 answers

jQuery('#ListBoxA,#ListBoxB,#ListBoxC').attr('disabled','disabled'); (Without spaces).

To enable use jQuery('#ListBoxA,#ListBoxB,#ListBoxC').removeAttr('disabled');

http://docs.jquery.com/Selectors/multiple#selector1selector2selectorN

+5
source

For another option, if you give them the whole CSS class, you can do:

jQuery('.ListBoxClass').attr('disabled', true);
+1
source

, , , ( "ListBox" id:

$("select[id*='ListBox']").attr('disabled',true);
+1
jQuery('select').each(function(){
    jQuery(this).attr('disabled','true');
});
0

Source: https://habr.com/ru/post/1722350/


All Articles