All TalkersCode Topics

Follow TalkersCode On Social Media - A Social Media Network for developers Join Now ➔

jQuery Check If Checkbox Is Checked

Last Updated : Mar 11, 2024

jQuery Check If Checkbox Is Checked

In this article we will show you the solution of jQuery check if checkbox is checked, here we are going to show you example for get checked checkbox state like whether checked or not with the help of is() method.

The is() method checks the current selection against an expression and returns true, if at least one element of the selection fits the given selector. If no element fits then it returns ‘false’.

Step By Step Guide On jQuery Check If Checkbox Is Checked :-

Here we defined html block with one input element ‘checkbox’ type with id attributes and a button ‘Click Here’ with id attribute.

In script block we defined ready() method which is automatically starts loading code of within this function when this program opened on browser and within that defined click() method with id ‘btn’ so which is refers when clicks on ‘Click Here’ click() event will load particular process.

There we defined is() method with input element ‘enable’ of id attribute in if condition which is checks checkbox state condition whether checked or not then alert message will displayed.

<!DOCTYPE html>
        <title>Checking Whether Checkbox is Checked</title>
        <script src=""></script>
                    alert("Checked is checked");
                    alert("Checked is not checked");
        <input type="checkbox" id="enable">Enable
        <button id="btn">Click Here</button>
  1. <!DOCTYPE html> tag which is instruct the web browser about what version of HTML file written in and it’s not have any ending tag.
  2. The<html> tag is used to indicate the beginning of HTML document.
  3. As above shown <head> tag is contain information about webpage and external file links are declared here. <title> tag is used for set the webpage title.
  4. Here we imported open source jquery library support file which is needed for coding using jquery in program.
  5. Both <head> and <title> tags having their pair end tag, so we need to close the ending tags respectively. If you’re not closed anyone of ending tag properly that is also affect the webpage result.
  6. <body> tag is beginning of main coding part because it contain coding of entire website blocks and elements described here.
  7. In script we defined ready() and click() method within that we used is() method as we know which is used for check checkbox state whether checked or not by specifying ‘:checked’ in this method which is appends with input element ‘#enable’, then respective alert message will display.
  8. So which process will begin when user clicks on button ‘Click Here’ id ‘btn’ after loading this on browser.
  9. In html block we defined input element checkbox ‘Enable’ with id ‘enable’ and a button ‘Click Here’ with id attribute ‘btn’.
  10. Both </body>,</html> tags closed respectively. </body> tag indicates the end of body, Then </html> tag indicates the end of HTML document.

Conclusion :-

In conclusion now we are able to know how to check checkbox state using jquery.

Before execution of program we needs to confirm internet connection because then only that jquery file will supports defined jquery codes without error.

When we executes program on browser we can see check box ‘Enable’ with button Click Here, user needs to clicks on it then alert message will appear as ‘Checked is checked’, otherwise we get result as ‘Checked is not checked’.

I hope this article on jQuery check if checkbox is checked helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Dikshita

Passionate Electronics and Communication Engineering student with expertise in web development (HTML, CSS, JS,PHP, Bootstrap, React.js) and content writing. Eager problem solver and tech enthusiast, adept at creating engaging web experiences.

Follow Dikshita On Linkedin 🡪