Friday, April 8, 2011

Disable DIV with jQuery

Here's a lame trick I use to disable divs:
// this works on IE // disable $('#myDiv').attr('disabled', 'disabled'); // enable $('#myDiv').attr('disabled', '');

Disabling the whole div doesn't seem to disable inputs in chrome and firefox though, so here's the alternative version drilling down to each single input elements:
// this works everywhere but looks weird in IE // disable $('#myDiv :input').attr('disabled', 'disabled');  // enable $('#myDiv :input').attr('disabled', '');

Good hacking.


->S.D<- said...

Thanks. It saved me a lot of time. Was wondering for a long time why the div was not disabled in Mozilla.

Anonymous said...'s work properly in Google Chrome.i save my time by using this code