How to check if the checkbox is checked using JavaScript?

Learn how to use JavaScript to check the state of the checkbox to see if it is selected

an examinationcheckedThe attributes of the element.

Suppose you have this checkbox:

<input type="checkbox" class="checkbox" />

You can check if it has been used

document.querySelector('.checkbox').checked

You can also check if you are looking for.checkbox:checkedDon't returnnull:

document.querySelector('.checkbox:checked') !== null

But i want to find.checkedCleaner.

Do not usegetAttribute()Look forcheckedThe attribute value, because if this check box is checked in this way by default, it will always be true:

<input type="checkbox" checked />

Don't checkvalueCheckbox element. Always soon, Regardless of whether the check box is checked or not.

Download mine for freeJavaScript beginner's manual


More browser tutorials: