Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable all controls on a page except controls in a particular div using jquery

Tags:

jquery

I want to disable all controls in a page using jquery except controls contained in a particular div.

 $('input,select,textarea,div:not("#viewNotice")').attr('disabled', 'disabled');

I have tried using above selector, but its not working good. Here I am disabling all input, select and textarea controls leaving viewNotive div.

Note: In viewNotice div I have a JqGrid. I dont want to disable jqgrid.

like image 773
Vaibhav Jain Avatar asked Aug 31 '25 17:08

Vaibhav Jain


1 Answers

You should consider using something like a modal layer instead. This would be much simpler in many ways. However, you can try the following:

$(':input').not('#viewNotice :input').attr('disabled', true);

The selector you used selected all divs that did not have an id of viewNotice (amongst other elements). This piece of code selects all input elements (see jQuery's selector API for :input) and excludes all inputs that are contained in #viewNotice afterwards.

like image 87
jwueller Avatar answered Sep 02 '25 07:09

jwueller