开发者

How do I create an array (which I can query against) of existing jQuery-objects

I have following code

var $radio1 = $('#FOO1');
var $radio2 = $('#FOO2');
var $radio3 = $('#FOO3');

Now I would like to to sth like

var $radios = $($radio1, $radio2, $radio3);
var $selectedRadio = $radios.filter(':checked');

I know that this w开发者_运维问答on't work, but could anyone give me a hand with this?

To clarify:

  • I do not want to use jQuery.each or any alikes as I would like to use selectors (if possible)...
  • I do not want to use groups, as I would like to use this with several groups, or no groups, ...
  • I do not want to use id-selectors for the array (eg. $('#FOO1, #FOO2, #FOO3');), as I would like a more generic solution


You can combine it in several ways:

var $radios = $("#FOO1, #FOO2, #FOO3");
var $selectedRadio = $radios.filter(':checked');

or

var $selectedRadio = $radio1.add($radio2).add($radio3).filter(':checked');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜