
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to check whether a checkbox is checked with JavaScript?
To check whether a checkbox is checked with JavaScript, the code is as follows −
Example
<!DOCTYPE html> <html> <head> <h1>Displaying textBox when a checkbox is checked</h1> Checkbox: <input type="checkbox" class="check" onclick="checkFunction()" /> <h2 class="textBox" style="display:none">Checkbox is checked!!!</h2> <script> document.querySelector(".check").addEventListener("click", checkFunction); function checkFunction() { var checkBox = document.querySelector(".check"); var textBox = document.querySelector(".textBox"); if (checkBox.checked == true) { textBox.style.display = "block"; } else { textBox.style.display = "none"; } } </script> </body> </html>
Output
This will produce the following output −
On clicking the checkbox −
- Related Articles
- How to check whether a checkbox is checked in JavaScript?
- How do I check whether a checkbox is checked in jQuery?
- How to set “checked” for a checkbox with jQuery?
- How to check whether a Button is clicked with JavaScript?
- How to check whether a radio button is selected with JavaScript?
- HTML DOM Input Checkbox checked Property
- How to change a specified cell value or color when checkbox is checked in Excel?
- How to check whether a JavaScript date is valid?
- Checking a Checkbox with JavaScript
- How to check a checkbox in a page in Selenium with python?
- How to check whether a value is a number in JavaScript?
- How to handle when checkbox 'checked state' changed event in jQuery?
- How to check whether an array is a true array in JavaScript?
- How to check whether a number is finite or not in JavaScript?
- How to check whether a NaN is a NaN or not in JavaScript?

Advertisements