Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.0.0.js"></script>
  Header<input type="checkbox" class="header-checkbox" /><br>
<input value="25" class="checkboxClass" type="checkbox" />
<input value="23" class="checkboxClass" type="checkbox" />
<button class="button">Click</button>
</body>
</html>
 
var checkedArray=[];
$(document).on('change','.checkboxClass',function(){
  if( $(this).is(':checked') )
  {
    //if checked add to array 
    checkedArray[checkedArray.length]=$(this).val();
  }else{
    //If unchecked remove the value from the array
    var index=checkedArray.indexOf($(this).val());
    if (index > -1) {
      checkedArray.splice(index, 1);
    }
  }
});
$(document).on('change','.header-checkbox',function(){
  
  
  if( $(this).is(':checked') )
  {
    //if checked add to array 
    $('.checkboxClass').each(function(){
      checkedArray[checkedArray.length]=$(this).val();
    });
  }else{
    //If unchecked remove the value from the array
    
    $('.checkboxClass').each(function(){
      var index=checkedArray.indexOf($(this).val());
      if (index > -1) {
        checkedArray.splice(index, 1);
      }
    });
    
  }
  
  
  
});
//then you can use it in click event
$('.button').click(function () {
var id = "";
//read checkedArray using for loop
alert(checkedArray);
});
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers