Take the 2-minute tour ×

This should be simple, but its not working for me :(
I am trying to print a value from JSON into an HTML table using jQuery.


jsFiddle: http://jsfiddle.net/S52XP/2/

Any idea what's wrong? If I alert the JSON element that I need in the table, it works! But I am not able to use it into the table using jQuery.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Why are you using <script> tags to print the name? Your jQuery works if you use a span instead:

<span id="company1name"></span>
share|improve this answer
Wow! That's so silly of me. Thanks for pointing out! :) –  Rahul Desai Dec 21 '12 at 22:28

Setting the html of a script tag does not work the way you expected. You can use some other element like a <p> or <span>, in this case I just set the ID on the <th> and <td> nodes.

Here's the jsfiddle with the loops working. http://jsfiddle.net/S52XP/3/

If you have the data in json, why not build the table out programmatically instead of using ID attributes all over the place?

share|improve this answer
That certainly saves lot of time! :) –  Rahul Desai Dec 21 '12 at 22:47

Your Answer


