JavaScript Answers

How to make a radio button unchecked by clicking it with JavaScript?

Spread the love

You can uncheck a radio button by setting its checked property to false using JavaScript.

To do this we write:


<input type="radio" id="radioButton" name="myRadioGroup" onclick="uncheckRadioButton()">
<label for="radioButton">Radio Button</label>


    function uncheckRadioButton() {
        const radioButton = document.getElementById('radioButton');
        radioButton.checked = false;

In this example, we have a radio button with the id "radioButton".

We’ve added an onclick event handler to the radio button that calls the uncheckRadioButton() function when it’s clicked.

In the uncheckRadioButton() function, we get the radio button element using document.getElementById('radioButton').

We set the checked property of the radio button to false, effectively unchecking it.

When you click the radio button, it will become unchecked.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *