Link to home
Start Free TrialLog in
Avatar of erzoolander
erzoolander

asked on

Build DOM elements from JSON / JQuery

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!
SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of erzoolander
erzoolander

ASKER

Gracias!