How to check and uncheck checkbox in JavaScript?

In this article, we will discuss how to check and uncheck checkboxes using JavaScript.

Explore different methods, including using the checked property, the click method, and jQuery.

So, let’s get started, to learn how to easily check and uncheck checkboxes in JavaScript with our comprehensive guide.

What is checkbox?

The checkbox is an HTML input element that enables the user to choose one option from a range of possibilities.

The checkbox can be created using the input element with the checkbox type attribute in JavaScript.

It is recommended to associate a label with the checkbox for better usability and accessibility. By doing so, clicking the label will also toggle the checkbox’s checked or unchecked state.

A checkbox has two possible states: ☑ checked and ☐ unchecked.

JavaScript can be used to check if a checkbox is selected, retrieve the values of selected checkboxes, and select or deselect all checkboxes.

To obtain the state of a checkbox, you can select the checkbox element using a DOM method like getElementById() or querySelector().

Then, you can access the checked property of the checkbox element. If the checked property is true, the checkbox is checked; otherwise, it is not.

Solutions on how to check and uncheck checkbox using JavaScript

Here are the following solutions on how to check and uncheck checkbox in JavaScript along with example codes and output.

1. Use checked property

To manipulate the checked status of a checkbox using JavaScript, this solution entails directly modifying the checked property of the checkbox element.

By setting it to true or false, the checkbox can be checked or unchecked. This approach offers a simple and direct method to manipulate the checkbox’s checked status.

Here’s an example:

<!DOCTYPE html>
<html>
<head>
    <title>Checkbox Example</title>
    <style>
        body {
            text-align: center;
            margin-top: 250px;
        }
    </style>
</head>
<body>
    <input type="checkbox" id="checkbox"> Try to Check me!
    <br><br>
    <button onclick="check()">Check</button>
    <button onclick="uncheck()">Uncheck</button>

    <script>
        function check() {
            document.getElementById("checkbox").checked = true;
        }

        function uncheck() {
            document.getElementById("checkbox").checked = false;
        }
    </script>
</body>
</html>

Output:

In this example, we modify some code to add some checklist:

<!DOCTYPE html>
<html>
<head>
    <title>Checkbox Example</title>
    <style>
        body {
            text-align: center;
            margin-top: 150px;
        }
        ul {
            list-style: none;
            padding: 0;
        }
    </style>
</head>
<body>
    <h2>Things to do:</h2>
    <ul>
        <li><input type="checkbox" id="eat"> Eat</li>
        <li><input type="checkbox" id="sleep"> Sleep</li>
        <li><input type="checkbox" id="work"> Work</li>
    </ul>

    <br><br>

    <button onclick="checkAll()">Check All</button>
    <button onclick="uncheckAll()">Uncheck All</button>

    <script>
        function checkAll() {
            document.querySelectorAll('input[type="checkbox"]').forEach(function(el) {
                el.checked = true;
            });
        }

        function uncheckAll() {
            document.querySelectorAll('input[type="checkbox"]').forEach(function(el) {
                el.checked = false;
            });
        }
    </script>
</body>
</html>

Output:


2. Use click method

Another simple method to manipulate the checked status of a checkbox using JavaScript is by invoking the click method of the checkbox element.

This solution allows you to toggle the checkbox’s checked status with just a single function call. It can be particularly useful when you need to quickly switch the checkbox between checked and unchecked states.

Here’s an example:

<!DOCTYPE html>
<html>
<head>
    <title>Checkbox Example</title>
</head>
<body>
    <style>
        body {
            text-align: center;
            margin-top: 250px;
        }
    </style>
    
    <input type="checkbox" id="checkbox"> Check me!
    <br><br>
    <button onclick="toggle()">Toggle</button>

    <script>
        function toggle() {
            document.getElementById("checkbox").click();
        }
    </script>
</body>
</html>

Output:

3. Use jQuery

This solution involves using the prop or attr methods provided by the jQuery library to check or uncheck a checkbox. This can be a convenient way to manipulate the checked status of a checkbox if you’re already using jQuery in your project.

Here’s an example:

<title>Checkbox Example</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
 <style>
        body {
            text-align: center;
            margin-top: 250px;
        }
    </style>

    <input type="checkbox" id="checkbox"> Check me!
    <br><br>
    <button onclick="check()">Check</button>
    <button onclick="uncheck()">Uncheck</button>

    <script>
        function check() {
            $("#checkbox").prop("checked", true);
        }

        function uncheck() {
            $("#checkbox").prop("checked", false);
        }
    </script>
</body>

Output

Conclusion

In conclusion, this article provides several approaches for checking and unchecking checkboxes using JavaScript.

The first approach demonstrated how to manipulate the checked property directly, setting it to true or false to check or uncheck the checkbox.

The second approach involved using the click method to toggle the checkbox’s checked status with a single function call.

Additionally, the article mentioned the use of jQuery’s prop or attr methods as an alternative for manipulating checkboxes if jQuery is already being used in the project.

Using these solutions offers flexibility and convenience for working with checkboxes in JavaScript.

We are hoping that this article provides you with enough information that helps you understand the JavaScript uncheck checkbox.

You can also check out the following article:

Thank you for reading itsourcecoders 😊.

Frequently Asked Questions

Is JavaScript still worth learning in 2026?
Yes. JavaScript runs on 98% of websites for the front-end, dominates the back-end via Node.js, powers mobile apps through React Native, builds desktop tools through Electron, and is the scripting layer for most AI tooling (LangChain.js, OpenAI SDK, Vercel AI). Whether you target web, mobile, AI, or full-stack capstones, JavaScript is the broadest single language you can learn.
What is the difference between var, let, and const?
var is function-scoped, hoisted to the top of its scope, and can be redeclared, which leads to bugs in modern code. let is block-scoped (only visible inside the nearest {}) and can be reassigned. const is block-scoped and cannot be reassigned, although object contents can still mutate. Default to const for everything, switch to let only when you actually need to reassign, and avoid var in any code written after 2017.
Which JavaScript version should I target in 2026?
Target ES2020 (ES11) as the safe baseline because every modern browser and Node.js 14+ supports it fully. ES2022 adds useful features like top-level await, private class fields with the # prefix, and the .at() array method. If you are writing for older browsers (IE11 or older Android WebViews), transpile down with Babel or use a build tool like Vite, esbuild, or webpack.
What is the best free editor for JavaScript?
Visual Studio Code is the industry standard, free, with built-in IntelliSense, debugger, terminal, Git, and a huge extension marketplace (ESLint, Prettier, GitHub Copilot, Tailwind). Install the JavaScript and TypeScript Nightly extension for the latest language features. JetBrains WebStorm is more powerful and free for students with a verified .edu email. For quick scratchpad work, the Chrome DevTools Sources panel includes a workspace and breakpoint debugger.
How do I run JavaScript locally vs in the browser?
In the browser: open DevTools with F12 (or right-click then Inspect), go to the Console tab, type or paste your code, press Enter. For HTML pages, add a script tag pointing to your .js file. Locally with Node.js: download Node from nodejs.org (LTS version), then run node script.js in your terminal from the file folder. Use the same Node setup for backend capstones, API integrations, and scripts that do not need a browser.
What can I build with JavaScript for my BSIT capstone?
Common BSIT capstones in JavaScript: full-stack web apps using React or Vue on the front-end with Node.js and Express on the back-end (MongoDB or MySQL for the database), real-time chat or notification systems using Socket.io, single-page dashboards with Chart.js or D3.js, cross-platform mobile apps with React Native, AI-powered chatbots using OpenAI SDK and LangChain.js, and Chrome extensions for productivity tools. Add Tailwind CSS for the UI and Vercel or Netlify for free deployment.
Caren Bautista

Technical Writer at PIES IT Solution

Responsible for crafting clear, well-structured, and beginner-friendly content across the platform. Handles the writing, proofreading, and editorial review of tutorials, guides, and documentation to ensure every article is accurate, readable, and easy to follow.

Expertise: Technical Writing · Content Creation · Documentation · Editorial Writing · JavaScript · TypeScript · Python · Python Errors · HTTP Errors · MS Excel  · View all posts by Caren Bautista →

Leave a Comment