jquery - Get td's value dynamically on click of a button -
i need value <td id='itemcadapreco'> when click on button id of 'btnremover':.
here jsfiddle: http://jsfiddle.net/6apax/
<tr id='itemcada'> <td id='itemcadaid'>1</td> <td>descrição aqui</td> <td id='itemcadaqtd'>12</td> <td id='itemcadapreco'>r$ 10,00</td> <td>r$ 12000,00</td> <td style='width: 15px;'><button id="btnremover">x</button></td> </tr> $(function(){ $("#btnremover").click(function(){ alert($(this).closest("#itemcadapreco").text()); }); }); edit: guys generated dynamically on loop , id "itemcadapreco" repeat, call id on click not work, need use 'closest' or that. thanks!
what might want
$(function(){ $("#btnremover").click(function(){ alert($(this).closest("tr").find('#itemcadapreco').text()); }); }); demo: fiddle
i'm assuming listing table same tr structure repeated, have problem because have multiple elements same id. id of element should unique in page, suggest change id attributes class.
<table id="tblitemdata"> <tr class='itemcada'> <td class='itemcadaid'>1</td> <td>descrição aqui</td> <td class='itemcadaqtd'>12</td> <td class="itemcadapreco">r$ 10,00</td> <td>r$ 12000,00</td> <td style='width: 15px;'><button class="btnremover">x</button></td> </tr> </table> $(function(){ $('#tblitemdata').on('click', '.btnremover', function(){ alert($(this).closest("tr").find('.itemcadapreco').text()); }); }); demo: fiddle
Comments
Post a Comment