user1661677
user1661677

Reputation: 1272

List JSON values in a list?

I'm trying to list v.name in <li>...</li> using this working function (it's currently listing the last name value and putting it in a single <li>).

$.getJSON(projectMedias, function (data) {
    $.each(data.medias, function (i, v) {
        var name = v.name;
        $('ul').html('<li>' + name + '</li>');
    })
});

Any help to get it to cycle through, and list all name values?

Upvotes: 0

Views: 21

Answers (1)

Anik Islam Abhi
Anik Islam Abhi

Reputation: 25352

.html() will replace previous content

Use .append() instead.

Convert this

$('ul').html('<li>' + name + '</li>');

to this

$('ul').append('<li>' + name + '</li>');

Upvotes: 1

Related Questions