Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an "or" attribute selector, like input[type=button|text]?

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 inputs and then filter them using .filter() but is there a more generic selector to select elements having one of a list of attributes?

like image 231
pimvdb Avatar asked May 12 '11 18:05

pimvdb


People also ask

What are attribute selectors?

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 (-).

What is a selector input?

<input type="password"> <input type="radio"> <input type="reset"> <input type="submit"> <input type="text">

How do I use attribute selectors?

[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.

How many types of attributes are there in CSS?

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.


2 Answers

Since you want to include everything except a few particular types, try this:

$('input:not([type=image],[type=button],[type=submit])') 
like image 111
Michael Haren Avatar answered Sep 18 '22 17:09

Michael Haren


$('input[type=text], input[type=checkbox], input[type=radio]').stuff(); 

or (taken from comments)

$('input:not([type=image],[type=button],[type=submit]') 
like image 26
drudge Avatar answered Sep 21 '22 17:09

drudge