Uncheck all JQuery radio buttonset at once

Using jQ-ui's buttonset feature

    $(function() {
        $( "#radio" ).buttonset();

    <div id="radio">
        <input type="radio" id="radio1" name="radio" /><label for="radio1">Choice 1</label>
        <input type="radio" id="radio2" name="radio" checked="checked" /><label for="radio2">Choice 2</label>
        <input type="radio" id="radio3" name="radio" /><label for="radio3">Choice 3</label>

Is there any way to uncheck all radio buttons of buttonset at once?


You can uncheck them them with the following (updated for jQuery UI 1.9:

$('#radio input').removeAttr('checked');
// Refresh the jQuery UI buttonset.                  
$( "#radio" ).buttonset('refresh');

Working JSFiddle.

You can match all the radio buttons and use prop() to uncheck them.

However, you also have to refresh the buttonset widget after doing so:

$("#radio").find("input:radio").prop("checked", false).end()

Before jQuery 1.6 version

$(':radio').attr('checked', false);  



After jQuery 1.6+

$(':radio').prop('checked', false);



Discovered this by accident...with jQuery 1.9.1 using a class name for the buttonset left all the buttons initially unset. Not yet sure if there are ramifications to this, but handy to know.

$( "div.myclass" ).buttonset();

<div id="myDiv" class="myclass">
    <input type="radio" name="myname" id="id1" value="1"><label for="id1">Label1</label>
    <input type="radio" name="myname" id="id2" value="2"><label for="id2">Label2</label>
    <input type="radio" name="myname" id="id3" value="3"><label for="id3">Label2</label>

That works for me

$('input:radio[name="RadioName"]').each(function () { $(this).attr('checked', false); });

Need Your Help

How to open html file?

python python-2.7 character-encoding

I have html file called test.html it has one word בדיקה.

How does Java solve retain cycles in garbage collection?

java garbage-collection

I know that a retain cycle (at least in Objective-C and Swift) is when two objects claim ownership of one another (they have references to each other). And in Objective-C we can solve the issue by