jquery - Get values of table row? -


here code:

html

<table class="table table-striped table-bordered table-condensed"> <thead>     <tr style='background-color: white'>         <th> <i class="fa fa-male"></i> name</th>         <th><i class="fa fa-bars"></i> particular</th>         <th><i class="fa fa-envelope-o"></i>unit</th>         <th><i class="fa fa-map-marker"></i>quantity</th>         <th><i class="fa fa-phone"></i>from</th>         <th><i class="fa fa-phone"></i>date</th>         <th><i class="fa fa-phone"></i>take actions</th>     </tr> </thead> <tbody>     <tr>         <td>sam</td>         <td>dsfjhfskdj</td>         <td>jhg</td>         <td>9</td>         <td>snehp</td>         <td>2014-03-21 08:55:59 utc             <td>                 <form action="/requisitions/1" class="button_to" method="post">                     <div>                         <input name="_method" type="hidden" value="delete" />                         <input class="btn btn-danger" data-confirm="are sure want delete?" type="submit" value="remove" />                         <input name="authenticity_token" type="hidden" value="lrkqigwpqmhvpzxjeimpmqzsevc8/sxd/piqi2r5hxs=" />                     </div>                 </form>                 <form action="/po" class="button_to" method="get">                     <div>                         <input class="btn btn-info" data-confirm="really wants generate po?" id="po" type="submit" value="po" />                     </div>                 </form>                 <form action="/capax" class="button_to" method="get">                     <div>                         <input class="btn btn-warning" data-confirm="are sure?" type="submit" value="capax" />                     </div>                 </form>             </td>             <tr>                 <tr>                     <td>mpobile</td>                     <td>rhyhjfryhn</td>                     <td>dh</td>                     <td>5</td>                     <td>snehp</td>                     <td>2014-03-21 09:48:01 utc                         <td>                             <form action="/requisitions/2" class="button_to" method="post">                                 <div>                                     <input name="_method" type="hidden" value="delete" />                                     <input class="btn btn-danger" data-confirm="are sure want delete?" type="submit" value="remove" />                                     <input name="authenticity_token" type="hidden" value="lrkqigwpqmhvpzxjeimpmqzsevc8/sxd/piqi2r5hxs=" />                                 </div>                             </form>                             <form action="/po" class="button_to" method="get">                                 <div>                                     <input class="btn btn-info" data-confirm="really wants generate po?" id="po" type="submit" value="po" />                                 </div>                             </form>                             <form action="/capax" class="button_to" method="get">                                 <div>                                     <input class="btn btn-warning" data-confirm="are sure?" type="submit" value="capax" />                                 </div>                             </form>                         </td>                         <tr>                             <tr>                                 <td>sssssss</td>                                 <td>sneh pandy</td>                                 <td>dkfgh</td>                                 <td>8</td>                                 <td>snehp</td>                                 <td>2014-03-21 10:01:52 utc                                     <td>                                         <form action="/requisitions/3" class="button_to" method="post">                                             <div>                                                 <input name="_method" type="hidden" value="delete" />                                                 <input class="btn btn-danger" data-confirm="are sure want delete?" type="submit" value="remove" />                                                 <input name="authenticity_token" type="hidden" value="lrkqigwpqmhvpzxjeimpmqzsevc8/sxd/piqi2r5hxs=" />                                             </div>                                         </form>                                         <form action="/po" class="button_to" method="get">                                             <div>                                                 <input class="btn btn-info" data-confirm="really wants generate po?" id="po" type="submit" value="po" />                                             </div>                                         </form>                                         <form action="/capax" class="button_to" method="get">                                             <div>                                                 <input class="btn btn-warning" data-confirm="are sure?" type="submit" value="capax" />                                             </div>                                         </form>                                     </td>                                     <tr> </tbody> </table> 

jquery

$(function(){          $('#po').click(function(){                   var $row = $(this).parents('tr');                  alert($row.find('td:eq(0)').html());                 alert($row.find('td:eq(1)').html());                 alert($row.find('td:eq(2)').html());                 alert($row.find('td:eq(3)').html());                 alert($row.find('td:eq(4)').html());          });     }); 

question:

when click on po button works first row not working other rows?

fiddle

you have duplicate id's , an id should unique , can use class instead -

also have nested tables need use closest -

var $row = $(this).closest('tr');  

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -