Jquery

How to select and unselect checkbox using jquery

Pinterest LinkedIn Tumblr

Here I am showing how to select and unselect all checkbox using jquery

Example:

<html lang="en">
<head>
	<title>Select and unselect all using jquery</title>
	<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
    <input name="tutorial_all" class="course-all" type="checkbox">Select All<br/>
    <input value="1" name="course" class="tutorial_list" type="checkbox">Course 1  
    <input value="2" name="course" class="tutorial_list" type="checkbox">Course 2  
    <input value="3" name="course" class="tutorial_list" type="checkbox">Course 3  
    <input value="4" name="course" class="tutorial_list" type="checkbox">Course 4  
    <input value="5" name="course" class="tutorial_list" type="checkbox">Course 5  
    <input value="5" name="course" class="tutorial_list" type="checkbox">Course 5  
    <input value="5" name="course" class="tutorial_list" type="checkbox">Course 5  
    <script type="text/javascript">
	    $('.course-all').on('change', function() {
	    	if(this.checked){
		    	$('.tutorial_list').prop('checked', true);  
	    	}else{
	    		$('.tutorial_list').prop('checked', false);
	    	}
		});
    </script>
</body>
</html>

Write A Comment