Monday, 16 November 2015

Jquery select all/de select all checkbox

Let us check how we can make select/deselect check box using Jquery.

Create a dynamic checkbox

<div class="wrapper"></div>
var _html = '<div class="list">
    <label><input type="checkbox" checked class="selectAll"> 

var _list = ['USA','India','China','England','Japan'];

for ( var i = 0; i < _list.length; i++ )
_html += '<div class="checkbox">
 <input type="checkbox" checked class="checkbox" value="' + _list[i] + '"/>' + _list[i] + '

_html += '</div>'


Select All/De Select All features

  $(".checkbox").find(':checkbox').prop("checked", this.checked);  

Now you can see that select all/de select all feature is working fine .But if we unselect one of the checkbox then the master check box also need to uncheck and also if we select all check box master should also checked .For making this possible add below code as well.

 var _totalChecked = $('.checkbox').find('input:checked').length;
 if(_totalChecked == _list.length){
  $(".selectAll").prop("checked", true);
  $(".selectAll").prop("checked", false);


Related Posts

1. Angular select all/de select all checkbox.

2. How to check lowercase in indexOf of an Array

3. Covert string to camel case using javascript

4. How to remove duplicate from an array and get count of duplicated .

No comments :

Post a Comment