Skip to main content

jQuery Set + Unset Radio Buttons

By Sam Deering

JavaScript

Share:

Free JavaScript Book!

Write powerful, clean and maintainable JavaScript.

RRP $11.95

Simple jQuery code snippets to set and unset input values on radio buttons. Just thought I would share because I was having a few issues with earlier versions of jQuery and setting radio buttons on a form.

//jQuery Set Radio Button
$('input[name="correctAnswer"]').attr('checked', false);

//To unselect the button
$("[name=color]").removeAttr("checked");

//jQuery (1.4+) code to pre-select one button :
var presetValue = "black";
$("[name=color]").filter("[value="+presetValue+"]").attr("checked","checked");

Related Articles

Sam Deering has 15+ years of programming and website development experience. He was a website consultant at Console, ABC News, Flight Centre, Sapient Nitro, and the QLD Government and runs a tech blog with over 1 million views per month. Currently, Sam is the Founder of Crypto News, Australia.

New books out now!

Learn the basics of programming with the web's most popular language - JavaScript


A practical guide to leading radical innovation and growth.

Integromat Tower Ad