Check If a Radio Button Is Checked with JavaScript

10/13/2021
Contents
In this article, you will learn how to check if a radio button is checked with JavaScript.
The checked Property
To check if a radio button is checked, the JavaScript checked property.
This property returns a Boolean value indicating whether the radio button was checked.
If the radio button was checked, it returns true, otherwise it returns false.
The example is below.
const isChecked = element.checked; // true|false
Demo
Code
HTML
<form>
<input type="radio" id="radioBtn">
<label for="radioBtn">Web Designer</label>
<button id="btn">Check</button>
</form>
JavaScript
const btn = document.getElementById('btn');
const rb = document.getElementById('radioBtn');
btn.addEventListener('click', () => {
if (rb.checked) {
alert("Checked");
} else {
alert("Unchecked");
}
});