1

I'm trying to iterate thru a list of radio butons in order to find the matching labels and constructing a new object from them, but with this code I'm only getting the first label

$target=$();

$radio.each(function(){
    $target = $target.add($source.children('label[for="'+$radio.attr("id")+'"]'));
})
0

1 Answer 1

2

$radio.attr("id") will only get the first elements id in the collection.. try using $(this) or the second argument in the .each() function(index,Element)

$radio.each(function(){
    $target = $target.add($source.children('label[for="'+$(this).attr("id")+'"]'));
})

or

$radio.each(function(i,v){
    $target = $target.add($source.children('label[for="'+$(v).attr("id")+'"]'));
})

you can even access it directly by doing this.id or v.id instead of using .attr('id')

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this did it!.. and also thanks for the this.id advice. ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.