- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to check/uncheck checkboxes using JavaScript
Following is the code to check/uncheck checkboxes using JavaScript −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } </style> </head> <body> <h1>Check/uncheck boxes using JavaScript</h1> <input class="check" type="checkbox" /> <button class="Btn">Toggle</button> <script> let BtnEle = document.querySelector(".Btn"); let checkEle = document.querySelector(".check"); BtnEle.addEventListener("click", () => { if (checkEle.checked === true) checkEle.checked = false; else checkEle.checked = true; }); </script> </body> </html>
Output
On clicking the toggle button, the checkbox will be toggled −
- Related Articles
- How to make checkboxes impossible to check in jQuery?
- How to change my code to uncheck radio button from JavaScript to jQuery?
- How to select checkboxes using selenium java webdriver?
- How to get the total number of checkboxes in a page using Selenium?
- POST unchecked HTML checkboxes
- Python Program to Check String is Palindrome using Stack
- Use jQuery to get values of selected checkboxes?
- Container for checkboxes in Bootstrap
- JavaScript program to check if a given year is leap year
- C++ Program to Check for balanced paranthesis by using Stacks
- Program to check valid mobile number using Java regular expressions
- C++ Program to Check the Connectivity of Undirected Graph Using BFS
- C++ Program to Check the Connectivity of Directed Graph Using BFS
- C++ Program to Check the Connectivity of Undirected Graph Using DFS
- C++ Program to Check Cycle in a Graph using Topological Sort

Advertisements