I have the following HTML table
<table>
<tr class="trSelected">
<td>One</td>
<td>two</td>
</tr>
</table>
I just want to get the text
in the second column
(ie,'two
')
I tried
$('.trSelected td').eq(2).val()
but it returs an empty string How it is possible through jQuery?
You should use the following construction:
$('.trSelected td').eq(1).text()
or
$('.trSelected td:eq(1)').text()
eq
selector uses zero-based index. Also you have to use text
method, not val
.
List Indices start from 0, not from 1.
You are trying to select column 3, which does not exist. Also, the .val() method is only used for getting and setting form fields, not normal html elements. Use .text() instead!
$('.trSelected td').eq(1).text()
might work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With