The following on page load successfully checks all checkboxes:

```
(function($){

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

}(jQuery));

```

But when running it inside a click event of a button it doesn't, the html value and alert successfully work though so the if statement does work.

```
$('#selectAll').click(function(){
                 if($(this).html() == 'Check All'){
                     $(':checkbox').prop("checked",true);
                     $(this).html('Uncheck All');
                     alert('check all');
                 }
                 else{
                     $(':checkbox').prop("checked",false);
                     $(this).html('Check All');
                     alert('uncheck all');
                 }
            });

```

The below edit shows the html as requested. I believe something is interfering with it as originally said the line to check the checkbox works outside of the if statement. The if statement works and changes the html value of the button. The check the checkbox line does not work inside the if statement though. I was using Datatables.js but have disabled it on this table in case that was having an affect.
EDIT (HTML):

```
<form method="POST" action="http://dev.co.uk/dashboard/export" accept-charset="UTF-8" role="form" class="form-horizontal"><input name="_token" type="hidden" value="fY87JvJYUjeHySDA9kmE72v2I9INRom1X63JyrKr">
<button type="button" class="btn green" id="selectAll">Check All</button>
<button type="submit" class="btn blue">Export</button>
<table class="table table-striped table-bordered table-hover" id="export">
<thead>
<tr>
<th>Select</th>
<th>Sku</th>
<th>Title</th>
<th>Belongs to</th>
<th>Brand</th>
<th>Category(s)</th>
<th>Description</th>
</tr>
</thead>
<tbody>

<tr>
<td> <label><input class="form-control selectAll" name="products[]" type="checkbox" value="1">  </label> </td>
<td> Product1 </td>
<td> Red T-shirt </td>
<td> T-Shirts </td>
<td> EZ T </td>
<td> Clothing, </td>
<td> Blurb goes here </td>
</tr>

<tr>
<td> <label><input class="form-control selectAll" name="products[]" type="checkbox" value="2">  </label> </td>
<td> Product2 </td>
<td> blue T-shirt </td>
<td> T-Shirts </td>
<td> EZ T </td>
<td> Clothing, </td>
<td> Blurb goes here </td>
</tr>

<tr>
<td> <label><input class="form-control selectAll" name="products[]" type="checkbox" value="3">  </label> </td>
<td> Product3 </td>
<td> green T-shirt </td>
<td> T-Shirts </td>
<td> EZ T </td>
<td> Clothing, </td>
<td> Blurb goes here </td>
</tr>

<tr>
<td> <label><input class="form-control selectAll" name="products[]" type="checkbox" value="4">  </label> </td>
<td> Product4 </td>
<td> Purple T-shirt </td>
<td> T-Shirts </td>
<td> EZ T </td>
<td> Clothing, </td>
<td> Blurb goes here </td>
</tr>
</tbody>
</table>

```