David C
David C

Reputation: 3739

How do I chain multiple selectors with filters in jQuery?

I'm trying to select multiple elements which do not have the attribute 'disabled' but I'm not sure if there's an easier way to type this:

$('input:not(:disabled), select:not(:disabled), textarea:not(:disabled)')

It seems a little wasteful to be typing multiple 'not(:disabled)'.

Upvotes: 1

Views: 1378

Answers (3)

nnnnnn
nnnnnn

Reputation: 150020

Have you tried the .not() method:

$('input, select, textarea').not(':disabled')

Which can be further simplified to:

$(':input').not(':disabled')

(Note that the ':input' selector selects button elements in addition to input, select and textarea elements.)

Upvotes: 0

Blender
Blender

Reputation: 298106

This should work:

$('input, select, textarea').filter(':enabled');

Or if you want to get really short:

$(':input:enabled')

Upvotes: 4

Omer Bokhari
Omer Bokhari

Reputation: 59578

you can use the :input selector along with the .not() method

$(':input').not(':disabled')

Upvotes: 0

Related Questions