javascript - How to get row data of a html table in jquery? -


$("#tbltest td:nth-child(3) a").click(function (event) {                             event.preventdefault();        var $td = $(this).closest('tr').children('td');        document.getelementbyid('id').value = $td.eq(0).text();        document.getelementbyid('appname').value = $td.eq(1).text();                         }); 

i use ans , working fine problem in td have 2 buttons(edit , delete) on click of edit function working. delete button not deleting data bcz buttonclk event not working bcz of function. plz suggest ans..

it easier answer if had posted html, i'm guessing looks this:

<table id="tbltest"> ... <td> <!-- third td in #tbltest (#tbltest td:nth-child(3)) -->     <a ...>edit</a>     <a ...>delete</a> </td> </table> 

your jquery selector looking -tags in third element. function calls event.preventdefault(). problem match both buttons when want match edit button. easy solution add class edit button , add class selector, function triggered edit button. how solve it:

<table id="tbltest"> ... <td>     <a ... class="edit_button">edit</a> <!-- add class edit button. -->     <a ...>delete</a> </td> </table>  // trigger edit button. $("#tbltest td:nth-child(3) a.edit_button").click(function (event) {      ... } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -