select - Checking all checkboxes in a table using jQuery -


my table looks following :

<table id="tableone" class="yui">     <thead>         <tr>             <th>                 <div><input type="checkbox" /></div>             </th>             <th>                 <div>name</div>             </th>             <th>                 <div>english</div>             </th>             <th>                 <div>spanish</div>             </th>             <th>                 <div>math</div>             </th>             <th>                 <div>history</div>             </th>         </tr>     </thead>     <tbody>         <tr>             <td>                 <div><input type="checkbox" /></div>             </td>             <td>                 <div>bob smith</div>             </td>             <td>                 <div>80</div>             </td>             <td>                 <div>70</div>             </td>             <td>                 <div><input type="checkbox" /></div>             </td>             <td>                 <div><input type="checkbox" /></div>             </td>         </tr>         <tr>             <td>                 <div><input type="checkbox" /></div>             </td>             <td>                 <div>george jones</div>             </td>             <td>                 <div>90</div>             </td>             <td>88</div>             </td>             <td>                 <div><input type="checkbox" /></div>             </td>             <td>                 <div><input type="checkbox" /></div>             </td>         </tr>     </tbody> </table> 

i using following javascript check/uncheck checkboxes in first column on click of checkbox in header.

$(document).ready(function() {     $("#tableone thead tr th:first input:checkbox").click(function() {         var checkedstatus = this.checked;         $("#tableone tbody tr td:first-child input:checkbox").each(function() {             this.checked = checkedstatus;         });     }); }); 

it isn't working. when click on checkbox of header, checkboxes in first column aren't getting selected. know doing wrong here. because <tr> tags in <div> , need provide <div> somewhere while selecting. can't figure out put in div in javascript. have tried out few combinations, don't seem work.

help please.

edit : have multiple tables in html page , want table affected. also, checkboxes first column need checked.

edit again : sorry, table getting rendered in above manner. changed table html.

your html code broken, make code fail in browsers, including internet explorer. can't have div tags around table cells.

different browsers handle broken code differently. firefox example moves div tags outside table, there don't break code. internet explorer moves table cells outside div tags, there still broken nameless tag inside table rows before table cells, :first-child selector doesn't work table cell not first child in table row.

if remove div tags, works fine: http://jsfiddle.net/guffa/jkxnf/1/

tested in ie9, firefox, chrome, safari, opera


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -