I am wondering what is the correct way to read values from a html table in jQuery?
Here is my HTML code:
<table>
<tr>
<td id="final">[['1.48E+02', '1.79E+03', '2.16E+04', '2.61E+05', '3.15E+06', '3.81E+07', '4.60E+08', '5.56E+09', '6.72E+10', '8.12E+11'], ['1.20E+01', '1.48E+02', '1.79E+03', '2.16E+04', '2.61E+05', '3.15E+06', '3.81E+07', '4.60E+08', '5.56E+09', '6.72E+10']]</td>
</tr>
</table>
jquery selector:
var s1 = $.parseJSON($('#final').text());
// I have tried .val(), .html(), but those did not work.
However, if my HTML is written in this way, then the jquery code works:
<table>
<tr>
<td id="final">[[148.0, 1788.0, 21604.0, 261036.0, 3154036.0, 38109468.0, 460467652.0, 5563721292.0, 67225123156.0, 812265199164.0], [12.0, 148.0, 1788.0, 21604.0, 261036.0, 3154036.0, 38109468.0, 460467652.0, 5563721292.0, 67225123156.0]]</td>
</tr>
</table>
Can anyone help me with my jquery code for the first HTML situation? Thanks!
You could just try using eval:
JsFiddle Example
I find eval isn’t too bad as long as you control the content that you put in the eval.
The Eval Function.
Oh and also, please note if you don’t wanna use that, remember than in JSON you can’t use the single quote or it wont parse. You can always check for valid JSON here: http://jsonformatter.curiousconcept.com. It will tell you all the errors in your JSON