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
Post a Comment