How to check and uncheck checkbox using jQuery

To check a checkbox we can use the prop() method as:

HTML code

1
<body>
2
        <input id="checkbox" name="check1" type="checkbox" value="Check Here"/>Check me <br>
3
        <button id="check">Check</button>
4
        <button id="uncheck">Uncheck</button>
5
    </body>

Script code

01
<script>
02
            $(document).ready(function(){
03
                //check checkbox
04
                $('#check').click(function(){
05
                    $('#checkbox').prop('checked',true);
06
                });
07
 
08
                //uncheck checkbox
09
                $('#uncheck').click(function(){
10
                    $('#checkbox').prop('checked',false);
11
                });
12
            });
13
        </script>

When you click the Check button, the checkbox checked.

Try and enjoy it.

by admin

0 comments… add one

Leave a Comment

Next Post:

Previous Post: