Jquery : how to know which row is selected?
<p>I have a table with dynamically changing rows items. </p>

<p>Among the rows there is a small button / link for each unit.</p>

<p>Eg </p>

<pre><code>   Data1 | LinkButton
   Data2 | LinkButton
   Data3 | LinkButton 
   Data4 | LinkButton
   Data5 | LinkButton 
   Data6 | LinkButton
</code></pre>

<p>What i want is that when i click on the link button ,i need to know which row is selected?Can any one give me pointers on how that can be done? </p>

<p>You help will be greatly appreciated. </p>

<pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;link href="css/main.css" type="text/css" media="screen, projection" rel="stylesheet" /&gt;


&lt;/head&gt;
&lt;body&gt;&lt;center&gt;
        &lt;div id="message" style="display: none;"&gt;
        &lt;/div&gt;
        &lt;div id="waiting" style="display: none;"&gt;
            Please wait&lt;br /&gt;
            &lt;img src="images/ajax-loader.gif" title="Loader" alt="Loader" /&gt;
        &lt;/div&gt;
        &lt;form action=""  id="searchForm"&gt;
            &lt;label for="search"&gt;Matter Search:&lt;/label&gt; &lt;input type="text" name="search" id="search" /&gt;
            &lt;input type="submit" id="submit" value="Submit" /&gt;
            &lt;a href="#"&gt;Link&lt;/a&gt;
        &lt;/form&gt;

        &lt;div id="matterTableDiv"  style="display: none;"&gt;
            List of Matters
            &lt;table id="matterTable"   border="1"&gt;
                &lt;thead&gt;
                &lt;th&gt;Matter Names&lt;/th&gt;
                &lt;th&gt;Matter Number&lt;/th&gt;
                &lt;th&gt;Description&lt;/th&gt;
                &lt;th&gt;&lt;/th&gt;
                &lt;/thead&gt;
                &lt;tbody&gt;

                &lt;/tbody&gt;

            &lt;/table&gt;
        &lt;/div&gt;
        &lt;div id="matterDetailTableDiv" style="display: none;"&gt;
            Matter Detail Table
        &lt;/div&gt;
        &lt;script type="text/javascript" src="js/json2.js"&gt;&lt;/script&gt;
        &lt;script type="text/javascript" src="js/jquery-1.4.2.js"&gt;&lt;/script&gt;

        &lt;script type="text/javascript"&gt;

            $(document).ready(function(){


                $('#search').focus();

                $('#submit').click(function(){



                    $('#message').hide(200);
                    $("#matterTableDiv").hide(200);
                    $("#matterTable tbody").text("");
                    $('#waiting').show(200);
                    $('#searchForm').hide(200);
                    $.ajax({
                        type : 'POST',
                        url : 'post.php',
                        dataType : 'json',
                        data: {
                            search : $('#search').val()
                        },
                        success : function(data){
                            if(data.msg == "[]" ){
                                $('#waiting').hide(200);
                                $('#message').removeClass().addClass('error')
                                .text('There was an error.').show(200);
                                $('#searchForm').show(200);

                            }

                            $('#waiting').hide(200);
                            $('#matterTableDiv').removeClass().addClass((data.error === true) ? 'error' : 'success')
                            if(data.error == false){

                                var str = JSON.parse(data.msg);
                                $("#matterTableDiv").show(200);
                                //alert("List :" + str.length);
                                //alert("List :" + str.toString());
                                $("#matterTable").html();

                                $.each(str, function(key, value) {
                                    var tblRow =
                                        "&lt;tr&gt;"
                                        //+"&lt;td&gt;&lt;a id="+key+" href='#dbID="+value.dbID+"&amp;matID="+value.matterID+"&gt;"+value.matterInfoSortName+"&lt;/a&gt;&lt;/td&gt;"
                                        +"&lt;td&gt;"+value.matterInfoSortName+"&lt;/td&gt;"
                                        +"&lt;td&gt;"+value.matterInfoMatterNum+"&lt;/td&gt;"
                                        +"&lt;td&gt;"+value.matterInfoFileDesc+"&lt;/td&gt;"
                                        +"&lt;td&gt;&lt;input type='button' value="+value.matterInfoFileDesc+"&gt;&lt;/td&gt;"
                                        +"&lt;/tr&gt;";
                                    $(tblRow).appendTo("#matterTable tbody");
                                    //alert(key + ': ' + value.matterInfoSortName);

                                });

                                $("button").live("click",function(){
                                     var row = $(this).closest("tr");
                                     var rowIndex = row.index();
                                     alert(rowIndex);
                                });

                            }else{
                                $('#message').removeClass().addClass('error')
                                .text('There was an error.').show(200);
                            }

                            $('#searchForm').show(200);

                            if (data.error === true)
                                $('#searchForm').hide(200);
                        },
                        error : function(XMLHttpRequest, textStatus, errorThrown) {
                            $('#waiting').hide(200);
                            $('#message').removeClass().addClass('error')
                            .text('There was an error.').show(200);
                            $('#searchForm').show(200);
                        }
                    });

                    return false;
                });


            });


        &lt;/script&gt;

    &lt;/center&gt;
&lt;/body&gt;
</code></pre>

<p></p>
