Reading several guidelines for jQuery performance I discovered this functionality:
Instead of doing:
$('#legendGallery).draggable({containment:'#container'});
$('#caption').draggable({containment:'#container'});
$('#controls').draggable({containment:'#container'});
Do this:
$('#legendGallery, #caption, #controls').draggable({containment:'#container'});
(One call to the jQuery engine several actions applied)
I want to apply this concept to an array of checkboxes:
<input type="checkbox" class="largecheckbox" name="chk_wms[]" value="m1" />
<input type="checkbox" class="largecheckbox" name="chk_wms[]" value="m2" />
<input type="checkbox" class="largecheckbox" name="chk_wms[]" value="m3" />
<input type="checkbox" class="largecheckbox" name="chk_wms[]" value="m4" />
With the following code I want to disable several checkboxes:
$('input:checkbox[name="chl_wms\[\]"][value="m1"]', 'input:checkbox[name="chl_wms\[\]"][value="m2"]', 'input:checkbox[name="chl_wms\[\]"][value="m3"]).prop('disabled', true);
But it’s not working, no error and no action applied.
Is there a better way to define the selectors?
Is there a way to do that command using one single call?
Thanks!
There appears to be a typo in your selctors. Plus, the jQuery escape char is
\\, and each selector should be in one string. With that in mind it should be:By fixing that it should work.
An alternative method which would perform better than the attribute selector would be to use classes. Eg:
Or even better yet, use Ids: