I'm trying to select all input
elements on a page, but not the ones that are of type image
, button
or submit
. What came to my mind first was selecting all input
elements that are of type text
, then all of type checkbox
etc.
However, this isn't very elegant. I was wondering if there is any better technique here. What would be useful is a selector like input[type=text|checkbox|radio|password|etc]
, but this does not seem to be available.
I know I can also select all input
s and then filter them using .filter()
but is there a more generic selector to select elements having one of a list of attributes?
CSS [attribute|="value"] Selector The [attribute|="value"] selector is used to select elements with the specified attribute, whose value can be exactly the specified value, or the specified value followed by a hyphen (-).
<input type="password"> <input type="radio"> <input type="reset"> <input type="submit"> <input type="text">
[attribute$=”value”] Selector: This selector is used to select all the elements whose attribute value ends with the specified value. The value doesn't need to be a whole word. [attribute*=”value”] Selector: This selector selects all the elements whose attribute value contains the specified value present anywhere.
The Seven Different Types. Attribute selectors are case-sensitive by default (see case-insensitive matching below), and are written inside brackets [] . There are seven different types of matches you can find with an attribute selector, and the syntax is different for each.
Since you want to include everything except a few particular types, try this:
$('input:not([type=image],[type=button],[type=submit])')
$('input[type=text], input[type=checkbox], input[type=radio]').stuff();
or (taken from comments)
$('input:not([type=image],[type=button],[type=submit]')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With