Jquery looks up the tr td sample simulation

  • 2020-03-30 02:54:09
  • OfStack

Today someone suddenly asked me in the group of $(" # MainContent_GridView1 "). The closest (" tr "). The children (" td: eq (1) "). The text () do not check this statement how to value. I asked him whether to take the td text of eq(1) under tr or all of them. He said all the... Then you must loop through all tr and find td from it...

Here I write a simple blog for those who don't know how to use jquery selectors.

I simulated a table out, for your reference, the following is the HTML structure
 
<table id="MainContent_GridView1"> 
<tbody> 
<tr> 
<td>1</td> 
<td>2</td> 
<td>3</td> 
</tr> 
<tr> 
<td>11</td> 
<td>22</td> 
<td>33</td> 
</tr> 
<tr> 
<td>111</td> 
<td>222</td> 
<td>333</td> 
</tr> 
</tbody> 
</table> 

//I introduced the local jquery file, but not the article.

<script type="text/javascript"> 
$(function () { 

//First find the table id of MainContent_GridView1, then find all the tr under the tbody and then loop each, $(this) represents the tr under the current loop,children is the td under tr and then select the index is 1 and then text() will come out.

$("#MainContent_GridView1 tbody tr").each(function (i) { 
alert($(this).children("td:eq(1)").text()); 
}); 
}) 
</script> 

Related articles: