Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncheck all JQuery radio buttonset at once

Tags:

Using jQ-ui's buttonset feature

<script>     $(function() {         $( "#radio" ).buttonset();     });     </script>       <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>     </div> 

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

like image 612
heron Avatar asked Jul 25 '12 09:07

heron


People also ask

How to uncheck all radio buttons in javascript?

To set a radio button to checked/unchecked, select the element and set its checked property to true or false , e.g. myRadio. checked = true . When set to true , the radio button becomes checked and all other radio buttons with the same name attribute become unchecked.

Can we uncheck radio button?

It is not a mandatory field. Radio button helps in ensuring only one option is selected. However, it doesn't allow user to deselect the option.

How do I make radio buttons not checked by default?

You can check a radio button by default by adding the checked HTML attribute to the <input> element. You can disable a radio button by adding the disabled HTML attribute to both the <label> and the <input> .


1 Answers

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.

like image 134
Michael Robinson Avatar answered Sep 16 '22 17:09

Michael Robinson