The following is a response from an Ajax call. How can I select the second and the sixth <td></td>
element using jQuery and get the value out of it?
<div>
<div>
<div>
<div>
<table>
<tr>
<td>Label 1</td>
<td>The value I need</td>
<td>Label2</td>
<td>2</td>
<td>Label 3</td>
<td>The value I need</td>
<td>Label 4</td>
<td>4</td>
</tr>
</table>
</div>
</div>
</div>
</div>
7
Answers
You don’t need jQuery for that. Pure Javascript (ES5) works fine. (IE 9+)
and
You can read more about Element.getElementsByTagName(), ParentNode.children and Node.innerText
as jquery:
im assuming that what you want to get is not the value but the text content inside the tag instead. you need to specify an id to your
then inside your script do
make sure to import jquery cdn in your head tag or above the script
You can use
querySelector
to do this:You could also just get the table, then drill down from there.
Or jump right to the row, and go from there.
You can use ":nth-child()" selector, so for your case is $("td:nth-child(2)")
You can try this –
please see: .get() | jQuery API Doc