0

I have a table like this

<tr class="odd">
    <td class="  sorting_1">opps</td>
    <td class="center "> <a href="#" onclick="tst(this)" class="btn btn-warning">
    <i class="icon-edit icon-white">      
    </i> Edit</a>

    </td>
</tr>

On click of that hyperlink i need the td values of the row.

This javascript i tried

 $(document).ready(function () {
     $("#tblTest td:nth-child(2)").click(function (event) {
         //Prevent the hyperlink to perform default behavior
         event.preventDefault();
         var $td = $(this).closest('tr').children('td');
         var sr = $td.eq(0).text();
         alert(sr);
     });
 });

This one works if i put in Table click event. I need on click of that hyperlink it should happen. How to achieve this ? Thanks in Advance.

without iterating row by row if any method is there to get it ?

2 Answers 2

1

You are binding click event to td bind it to a

Change

$("#tblTest td:nth-child(2)").click(function (event) {

To

$("#tblTest td:nth-child(2) a").click(function (event) {
Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

$("a.btn").click(function (event) {
    //Prevent the hyperlink to perform default behavior
    event.preventDefault();
    var $td = $(this).parent().closest('tr').children('td');
    var sr = $td.eq(0).text();
    alert(sr);
});

DEMO HERE

5 Comments

Its the class name for the link you have, <a href="#" onclick="tst(this)" class="btn btn-warning">
some where i went wrong ? i didn't remove that previous function also. may be that's reason ?
Try to remove the onclick attribute from the link
yeah removed and tested same result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.