tags:

views:

48

answers:

3

Hello, $('#myTable tr:last'); i get a tr content(without tr tag). how can i get tr attribute? I can't. then tried to get attribute er from first td on clicked row. and now same problem.

$('#myTable tr').click(function() {
   var State = $(this).find("td:first-child").attr("er"); // this code is false
   alert(State);
});

My HTML

             <table width="600px" cellspacing="0" border="1" id="myTable">
                <tr>
                    <th>
                        ...
                    </th>
                    <th>
                        ...
                    </th>
                    <th>
                        ...
                    </th>
                    <th>
                        ...
                    </th>
                    <th>
                        ...
                    </th>
                    <th>
                    !
                    </th>
                </tr>
                <tr bgcolor="#484848">
                    <td width="152px;" class="textField" er="editable">
                        <input type="text" value="" />
                    </td>
                    <td width="350px;">
                        <textarea cols="40" rows="3"></textarea>
                    </td>
                    <td>
                        <select disabled="disabled">
                            //options
                        </select>
                    </td>
                    <td width="152px;">
                        <input type="text" />
                    </td>
                    <td>
                        <input type="checkbox" />
                    </td>
                    <td>
                    </td>
                </tr>
            </table>
+1  A: 

Shouldn't it be $(this).find("td:first") ?

Romuald Brunet
yeas, you're right
loviji
A: 

You can get the tr attribute by using $(this).parent()

Hojo
if in my table row have attribute er I tried $(this).parent().attr("er"); but it does not work
loviji
+2  A: 

This works fine for me

$("#example tr:last").click(function() {
    console.log($(this).find("td:first"));
});

$("#example tr:last").click(function(){
    console.log($(this).attr("class"));
});

First event prints the first td in the last tr on click on the last tr.

Second event prints the class attribute in the last tr on click on the last tr.

Arun P Johny