Get the first child attr value

I have the following code for assigning onclick in the <tr> :

 $("#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 innerHTML. How can i do this?

+4
source share
6 answers

Do you want to do something like this

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

This will show you the content you are looking for :)

+4
source
 $(this).children(":first").html(); 
+5
source
 $("#tblDepartment tr").click(function() { alert($(this).children('td').first().html()); }); 
+4
source
 $(function(){ $(".trEven").click(function() { alert($(this).parent().find("td:first").html()); }); }); 

Working sample http://jsfiddle.net/H2gJV/7/

+2
source
 $("#tblDepartment tr").click(function() { alert($(this).eq(1).attr("field#ID").html()); }); 
+1
source

For completeness, here is the scope.

 $('#tblDepartment tr').click(function () { alert($('td[field=ID]', this).html()); }); 
+1
source

Source: https://habr.com/ru/post/1416575/


All Articles