Srinivas Sarda
Srinivas Sarda

Reputation: 59

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>

Upvotes: 2

Views: 2453

Answers (1)

guest271314
guest271314

Reputation: 1

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

Upvotes: 4

Related Questions