Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get data from table cell ID

Tags:

javascript

I have the following table. What do i need to use in JavaScript to read the number from the below cell named "number"?

<table>
<tr>
<td id="number">56656.87</td>
</tr>
</table>

I have tried the following however it does not work.

document.getElementById('number');
like image 710
JackTheJack Avatar asked Jan 18 '23 03:01

JackTheJack


2 Answers

Using raw JavaScript:

var text = document.getElementById('number').innerText;

Using jQuery:

var text = $('#number').text();
like image 170
Alex Avatar answered Jan 20 '23 04:01

Alex


The innerHTML property holds the contents of that cell. If you got [object Object] on your last attempt you're almost there. This is how you do it:

     var n = document.getElementById('number').innerHTML;

Make sure there's no other number id on that page.

like image 37
Silviu-Marian Avatar answered Jan 20 '23 03:01

Silviu-Marian