Srinivas Sarda Srinivas Sarda - 10 months ago 54
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.


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

Answer Source

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")