0

I have simple JSON array and each function:

var result= $.each(response.data, function(k, v) {
                console.log(k); 
            }); 

Now, this work fine, in my console I get all values from JSON. So, is there possibility for values of array show in my HTML page,in some div, etc:

<div id="my_div"> </div>

I try with append() and HTML functions, but always get blank div.

Thanks

Scott
  • 1,863
  • 2
  • 24
  • 43
pavlenko
  • 625
  • 2
  • 11
  • 30

2 Answers2

2

Html

<div id="my_div"></div>

Js

var theData = ['a','b','c','d'];

$.each(theData, function(k, v) {
    $('#my_div').append(v+'<br/>');
}); 

This answer may be useful too: https://stackoverflow.com/a/2342433/3052648

Community
  • 1
  • 1
MazzCris
  • 1,812
  • 1
  • 14
  • 20
1
var html = '';
var result= $.each(response.data, function(k, v) {
    html += "<span>" + k + "</span>"
    console.log(k); 
});
$("#my_div").append(html);
Ash
  • 2,108
  • 2
  • 17
  • 22
ozil
  • 6,930
  • 9
  • 33
  • 56