Answers for "js checkbox check event"

12

javascript event listener checkbox

//js
var checkbox = document.querySelector("input[name=checkbox]");

checkbox.addEventListener( 'change', function() {
    if(this.checked) {
        // Checkbox is checked..
    } else {
        // Checkbox is not checked..
    }
});

//jquery
$('input[name=checkbox]').change(function(){
    if($(this).is(':checked')) {
        // Checkbox is checked..
    } else {
        // Checkbox is not checked..
    }
});
Posted by: Guest on July-08-2020
8

dom check a checkbox

document.getElementById("myCheck").checked = true;
Posted by: Guest on March-01-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language