I thought this would be simple I have a table with the first column a checkbox
I am using this code to make the checkbox check all the other checkboxs
$('.checkall').click(function () {
$(this).parents('tbody:eq(0)').find(':checkbox').attr('checked', this.checked);
});
The HTML/Jquery code to create the table
$("#menuarea").html('<a href="#!/home" id="gotohome"><div id="backmain" class="backbg">Back</div></a><div id="nav" class="backbgright">New Business Lead</div>'+
'<div id="dowithleads"></div>'+
'<table cellpadding="0" cellspacing="0" border="0" class="sortable paginated" id="manageleads">'+
' <thead>'+
' <tr>'+
' <th class="small"><input type="checkbox" class="checkbox checkall" value="Yes"></th>'+
' <th class="sort-alpha">Created Time</th>'+
' <th class="sort-alpha">Company</th>'+
' <th class="sort-alpha">Lead Name</th>'+
' <th class="sort-alpha">Phone No.</th>'+
' <th class="sort-alpha bigger">Email</th>'+
' <th class="sort-alpha">Lead Owner</th>'+
' <th class="sort-alpha last">Lead Status</th>'+
' </tr>'+
' </thead>'+
' <tbody>'+
' <tr>'+
' <td class="small"><input type="checkbox" class="formbox"></td>'+
' <td>Mozilla 1.6</td>'+
' <td>Win 95+ / OSX.1+</td>'+
' <td class="center">1.6</td>'+
' <td class="center">A</td>'+
' <td class="center bigger">A</td>'+
' <td class="center">A</td>'+
' <td class="center last">A</td>'+
' </tr>'+
' <tr>'+
' <td class="small"><input type="checkbox" class="formbox"></td>'+
' <td>Mozilla 1.2</td>'+
' <td>Win 94+ / OSX.1+</td>'+
' <td class="center">1.5</td>'+
' <td class="center">D</td>'+
' <td class="center bigger">A</td>'+
' <td class="center">N</td>'+
' <td class="center last">A</td>'+
' </tr>'+
'</table>');
If you’re using jQuery 1.6.x, use
.prop:Also note that
$(this).parents('tbody:eq(0)')does not select anything. Your.checkallis not inside atbody. I changed it to$(this).closest('table').