Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get attr value of first child

Tags:

jquery

I have the follwing code for assigning onclick to a <tr> row:

$("#tblDepartment tr").click(function() {
       alert($(this).eq(1).attr("field"));
   });

My HTML code is here:

    <tr class="trEven" id="trDepartment4">
            <td field="ID" style="display: none;" width="50px">4</td>
            <td field="DEPT_NM" width="100%">BID DEPARTMENT</td>
    </tr>

What I would like to do is tget first child's innerHTML. How can I do that?

like image 869
Chetan Patel Avatar asked Dec 04 '22 03:12

Chetan Patel


2 Answers

$(this).children(":first").html();
like image 118
Aram Kocharyan Avatar answered Jan 04 '23 07:01

Aram Kocharyan


You want to do something like this

$("#tblDepartment tr").click(function() {
   alert($(this).children('td').first().html());
});

This will show you the content your looking for :)

like image 28
Undefined Avatar answered Jan 04 '23 08:01

Undefined