How to check and uncheck all the check boxes in just one click through jQuery ?

Description:- Through this example you can easily check all the check boxes of the list. So that you can delete them or you can perform whatever you want to do. This example includes jQuery file so download it from http://jquery.com/download/ or click on the link http://code.jquery.com/jquery-1.11.2.min.js  and save it in the same folder in which you are going to save this example.

<!DOCTYPE html>
<head>
<title>Check All</title>
<script src="jquery-1.11.2.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(e) {
    $("#selectall").click(function(e){
        if(this.checked)
        {
            $(".checks").each(function() {
                this.checked= true;
            });
        }
        else
        {
        $(".checks").each(function() {
                this.checked= false;
            });
        }
    });
});

</script>
<style>
ul{list-style:none;}
</style>
</head>
<body>
<ul>
    <li><input type="checkbox" id="selectall" name="selectall"/>Select All</li>
    <br/>
    <hr>
    <li><input type="checkbox" class="checks"/> Menu1</li>
    <li><input type="checkbox" class="checks"/> Menu2</li>
    <li><input type="checkbox" class="checks"/> Menu3</li>
    <li><input type="checkbox" class="checks"/> Menu4</li>
    <li><input type="checkbox" class="checks"/> Menu5</li>
    <li><input type="checkbox" class="checks"/> Menu6</li>
    <li><input type="checkbox" class="checks"/> Menu7</li>
    <li><input type="checkbox" class="checks"/> Menu8</li>
    <li><input type="checkbox" class="checks"/> Menu9</li>
</ul>


</body>
</html>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s