how to check if checkbox is checked in javascript code example
Example 1: How to check whether a checkbox is checked in jQuery?
if(document.getElementById('on_or_off_checkbox').checked) {
}
if($('#on_or_off_checkbox').is(':checked')){
}
Example 2: if checkbox is checked
if ($('#id_input').is(':checked')) { }
Example 3: oncheck checkbox javascript
<input type='checkbox' onchange='handleChange(this);'> Checkbox
function handleChange(checkbox) {
if(checkbox.checked == true){
document.getElementById("submit").removeAttribute("disabled");
}else{
document.getElementById("submit").setAttribute("disabled", "disabled");
}
}
Example 4: how to check if input is checked javascript
const cb = document.getElementById('accept');
console.log(cb.checked);