We help IT Professionals succeed at work.
Get Started

Build DOM elements from JSON / JQuery

erzoolander
erzoolander asked
on
84 Views
Last Modified: 2015-08-17
I've got a JSON string that takes this form...

{"people":[{"name":"person1","description":"This is a brief description of my service.","image":"mandg1.jpg","type":"first","insured":"yes","license":"N\/A","picture":"mandg1.jpg","yearsinbusiness":"8","distance":15},{"name":"person2","description":"This is a brief description of my service.","image":"mandg2.jpg","type":"second","insured":"yes","license":"N\/A","picture":"mandg2.jpg","yearsinbusiness":"8","distance":19}]}

What I'd like to do is, via jQuery, build a group of divs based upon the "people" key...so in the instance above...you'd end up creating 2 elements...and append them to the div id="container".  If there were 50 elements, you'd end up with 50 divs, etc etc etc.

<div id="container">
<div id="person1">
<p>Name: person1</p>
<p>Description: This is a brief description of my service</p>
</div>
<div id="person2">
<p>Name: person2</p>
<p>Description: This is a brief description of my service</p>
</div>
</div>

What would the jQuery syntax for that be?  Thanks in advance!
Comment
Watch Question
Top Expert 2011
Commented:
This problem has been solved!
Unlock 2 Answers and 3 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE