html - Row wise selecting the all checkboxes inside a table with using Jquery -
i have script should check checkboxes inside table row. using below post able check checkboxes inside table. don't want this. want check checkboxes in row wise only.
reference post:
jquery select checkboxes in table
sample html code:
<table> <tr> <th> <input type="checkbox" id="selectall" /> </th> <th> hi! </th> </tr> <tr> <td> <input type="checkbox" id="1"/> </td> <td> hi! </td> </tr> <tr> <td> <input type="checkbox" id="2"/> </td> <td> hi! </td> </tr> </table> sample jquery:
$('#selectall').click(function(e){ var table= $(e.target).closest('table'); $('td input:checkbox',table).prop('checked',this.checked); }); see below screenshots project
- before clicking check checkbox

- after checking check checkbox

looks have duplicate ids select checkboxes. ids must unique. can give same class select checkboxes(say selectall) , use class selector.
also targeting closest tr, can traverse closest tr rather getting table element. , find input checkboxes in them. this:
$('.selectall').click(function(e){ var tr= $(e.target).closest('tr'); $('td input:checkbox',tr).prop('checked',this.checked); });
Comments
Post a Comment