views:

50

answers:

4

I am using a jquery selector

$('input,select,textarea').not('table input').attr('disabled',true);

here I am disabling all input, select, and textarea control. but I dont need to disable any control that is in a table. I have done it using .not('table input') but I also need to mention select along with input control in a table.

I have select conrol in table, whcih i dont want to disable. what would be the selector for this.

+2  A: 
$('input,select,textarea').not('table input').not('table select').attr('disabled',true);
Anatoly G
+1  A: 
$('input,select,textarea').not('table input,table select').attr('disabled',true);
Haim Evgi
A: 

Nope, what you're doing there is adding some elements into a jQuery wrapped set and just after doing that, remove some of those elements again which obviously doesn't make much sense.

You should use a .filter() here.

$('input,select,textarea').filter(function(i){
   return $(this).closest('table').length === 0
}).attr('disabled', 'disabled');

Reference: .filter()

Example: http://www.jsfiddle.net/YjC6y/27/

jAndy
But filtering does exactly the same thing - remove some element form the collection. `filter` is simply a positive filter while `not` is a negative one.
Nux
+1  A: 

You could either use something like:

$('input,select,textarea').not('table input').not('table select').attr('disabled',true);

Or shorter:

$('input,select,textarea').not('table input,table select').attr('disabled',true);

But you could also add a class to all your inputs that are to be disabled and simply use:

$('.toBeDisabled').attr('disabled',true);

Or some not to be disabled:

$('input,select,textarea').not('.notToBeDisabled').attr('disabled',true);

Or if you want to include all form elements (also buttons), then use:

$(':input').not('table :input').attr('disabled',true);
Nux