0

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.

$('#company1name').html(companies[0].name);

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.

2 Answers 2

4

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

<span id="company1name"></span>
Sign up to request clarification or add additional context in comments.

Comments

2

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?

1 Comment

That certainly saves lot of time! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.