Stan Amsellem Stan Amsellem - 3 months ago 6
HTML Question

Can't extract the text of an html tag using jQuery

I am having trouble extracting content of an html tag through the chrome console. I think I am missing something pretty obvious but it's been half an hour I'm trying stuff and I can't make it work, so I'm asking help :)

I want to extract some code from that page: http://www.societe.com/societe/deezer-511716573.html

Here's the html snippet I'm interested in:

<table id="rensjur">
<tbody>
<tr>
<td>Dénomination</td>
<td>DEEZER</td>
</tr>
</tbody>
</table>


I want to extract the content "DEEZER" of the second < td >. I am using the following:

$("#rensjur tbody td:nth-child(2)").text();


but this raises an error:
Uncaught TypeError: $(...).text is not a function(…)


However, when I call:

$("#rensjur tbody td:nth-child(2)")


It gives me the right HTML tag:

<td>DEEZER</td>


How can I get only "DEEZER" as a result ? What am I doing wrong with the
text()
method ?

Answer

Use the innerHTML property; that will help.

Comments