Getting cell value from table in jQuery
I have a table with no id or name inside of a div. How do I read the value from the desired table cell in jQuery? For example:
<div id="myDiv" style="padding-top: 0px; height: 60px;">
<table width="264" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td width="80" height="20" style="font-size: 10px;">
</td>
<td id="the_cell_i_want" align="right" style="color: rgb(102, 188, 41); font-size: 24px;font-weight: bold; background-color: rgb(255, 255, 255); background-image: none;">THE_VALUE_I_WANT</td>
</tr>
<tr>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
I want to retrieve the cell with the id "the_cell_i_wan开发者_开发问答t" and it should return "THE_VALUE_I_WANT".
$("#the_cell_i_want").text();
will do it for you.
Since you have the id you can uniquely select the element from the DOM using the id selector. And you can get the cell value [innerText] using text.
精彩评论