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.
Howev开发者_如何学JAVAer, 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?
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]')
In CSS you can have selectors like:
input[type=text],input[type=checkbox],input[type=radio],input[type=password]
maybe this works in jQuery as well.
I know its old, but i feel the best elegant solution for this would be to give them a common class and then use that as a selector ?
The above answers are not entirely true.
When depending on a id (#) these methods seems to fail.
In my experience we need to add the id for each or
statement.
Like so:
$('#id input[type=text], #id input[type=checkbox], ...
精彩评论