将jQuery对象添加到空对象

将jQuery对象添加到空对象,jquery,arrays,object,collections,add,Jquery,Arrays,Object,Collections,Add,我试图遍历一个radio Buton列表,以找到匹配的标签并从中构造一个新对象,但是使用这段代码,我只得到第一个标签 $target=$(); $radio.each(function(){ $target = $target.add($source.children('label[for="'+$radio.attr("id")+'"]')); }) $radio.attr(“id”)将仅获取集合中的第一个元素id。。尝试使用$(this)或函数(索引,元素) 或 您甚至可以通过执

我试图遍历一个radio Buton列表,以找到匹配的标签并从中构造一个新对象,但是使用这段代码,我只得到第一个标签

$target=$();

$radio.each(function(){
    $target = $target.add($source.children('label[for="'+$radio.attr("id")+'"]'));
})
$radio.attr(“id”)将仅获取集合中的第一个元素id。。尝试使用
$(this)
函数(索引,元素)


您甚至可以通过执行
this.id
v.id
直接访问它,而不是使用
.attr('id')

谢谢,这样做了!。。同时也感谢您的建议
$radio.each(function(){
    $target = $target.add($source.children('label[for="'+$(this).attr("id")+'"]'));
})
$radio.each(function(i,v){
    $target = $target.add($source.children('label[for="'+$(v).attr("id")+'"]'));
})