Learning Horizon | For Learners

ASP.NET, SQL SERVER, JQUERY,JAVASCRIPT, WEBSPHERE

Wednesday 10 April 2013

Find Row Id Of Specific Row In Static Table Using Jquery

This tutorial explain you how to find id of a row when user clicks on a specific row in a table. Normally we need to get the row id to perform specific operation on a table row. And for beginners or new learner of jquery it is difficult to get row id of a table so I decided to write this two tutorial series to explain how to get row id especially when we are making dynamic tables.

Static Example:-
In the example we have a table having id=”tbl_Example” and Five rows. Every row has a specific id. e.g.

<table id="tbl_Example" border="1" >
        <tr id="Row0">
            <th>
                Serial Number</th>
            <th>
                Name</th>
        </tr>
        <tr id="Row1">
            <td>
                1</td>
            <td>
                Anwar</td>
        </tr>
        <tr id="Row2">
            <td>
                2</td>
            <td>
                Aslam</td>
        </tr>
        <tr id="Row3">
            <td>
                3</td>
            <td>
                Hammad</td>
        </tr>
        <tr id="Row4">
            <td>
                4</td>
            <td>
                Zahid</td>
        </tr>
        <tr id="Row5">
            <td>
                5</td>
            <td>
                Ashfaq</td>
        </tr >        
    </table>

   <script  type="text/javascript">

        $(document).ready(function () {
            $("#tbl_Example tr").click(function () {
                alert($(this).closest('tr').attr('id'));
            });

        });
    </script>

Note:- See my next tutorial on how to get row id of dynamic table when user click on specific row.

No comments:

Post a Comment

Please do not enter spam links.