jQuery: How can I select multiple elements from one path?
I'm curious if there is a way to condense this:
$('foo input:checkbox, foo input:radio');
I tried the following but no luck:
$('foo input[type="checkbox",type="radio"]');
This blindly doesn't work (prob bad syntax)
$('foo input[type="checkbox"][type=开发者_JAVA技巧"radio"]');
I think this would select all inputs that are both radio and checkbox, which won't ever be the case.
Edit:
I changedfooElement
to foo
toi simplify the example$('input[type="checkbox"], input[type="radio"]', $('fooelement'))
Or
$('[type="checkbox"], [type="radio"]', $('fooelement input'))
Or
$(':checkbox, :radio', $('fooelement input'))
Remember jQuery offers the abiltiy to specify a context to search in.
http://api.jquery.com/jQuery/
Try this
$('fooElement input').filter(":checkbox, :radio");
$('fooElement').find(':checkbox,:radio');
$('fooElement input[type="checkbox"]').add('fooElement [type="radio"]');
it's not really "condensed", per se, but:
$('fooElement input[type="checkbox"], fooElement input[type="radio"]');
精彩评论