Srinivas Sarda Srinivas Sarda - 29 days ago 6
jQuery Question

Disable all form elements except particular class

I'm new to JQuery.
I need to disable all from elements except with this class custom_specialcase.

Thanks

<div>
<button>B1</button><br>
<button class="custom_specialcase">B2</button><br>
<input type="checkbox" class="custom_specialcase"/>Checkbox1<br>
<input type="checkbox" />Checkbox2<br>
<input type="radio" class="custom_specialcase"/>Radio1<br>
<input type="radio" />Radio2<br>
<select class="custom_specialcase">Select
<option>1</option>
<option>1</option>
</select>
<select >
<option>2</option>
<option>2</option>
</select>
</div>

Answer

You can use selector "input, select, button" at call to jQuery(), .not() with selector ".custom_specialcase", .attr(), set disabled attribute to "disabled" at .ready() handler

$(function() {
  jQuery("input, select, button")
  .not(".custom_specialcase").attr("disabled", "disabled")
})