tags:

views:

24

answers:

2
<li>
<label><input type="radio" name="radio1" value="1">radio1</label>
<label><input type="radio" name="radio2" value="2">radio2</label>
...
</li>
<li>
....
</li>

I tried this but failed:

$('input[type="radio"]').click(function() {
    var $self = $(this);
    $.map($self.parents('li:first').find('input[type="radio"]'),function(n,i){
        if($(n) != $self)$(n).removeAttr('checked');
    });
});
+3  A: 

Use the not function to remove the current item from the selection:

$('input:radio').click(function() {
    $(this).closest('li').find("input:radio").not(this).removeAttr('checked');
});

But if you just name then the same, they become exclusive automatically.

<label><input type="radio" name="radio1" value="1">radio1</label>
<label><input type="radio" name="radio1" value="2">radio2</label>
Doug Neiner
A: 

You shouldn't need jQuery to make radio buttons exclusive, just give them the same name.

<label><input type="radio" name="radio1" value="1">radio1</label>
<label><input type="radio" name="radio1" value="2">radio2</label>

and you should be good.

Alex Sexton
I know this,but I can't this time