Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
165
rated 0 times [  167] [ 2]  / answers: 1 / hits: 12564  / 10 Years ago, thu, june 5, 2014, 12:00:00

I Have an object that looks like this:



{
qA: [
{
question: How deep is the ocean,
answer: [
quite deep,
very deep,
no deep at all
]
},
{
question: How high is the sky,
answer: [
real high,
high enough,
not that high
]
}
]
}


I want to load it into a ul where the question is the title of the ul and the answers are its li. How do I do that?


More From » jquery

 Answers
20

you can do with jquery like this:



$.each(data.qA, function (index, item) {
//console.log(item);
html += <ul> + item.question;

$.each(item.answer, function (index1, item1) {
html += <li> + item1 + </li>;

});
html+=</ul>;
});
$(#container).append(html);


FIDDLE DEMO


[#44783] Thursday, June 5, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
milo

Total Points: 62
Total Questions: 99
Total Answers: 97

Location: Sweden
Member since Mon, May 8, 2023
1 Year ago
;