开发者

jQuery: How can I select multiple elements from one path?

开发者 https://www.devze.com 2023-04-02 17:38 出处:网络
I\'m curious if there is a way to condense this: $(\'foo input:checkbox, foo input:radio\'); I tried the following but no luck:

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 changed fooElement 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"]');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号