My Javascript loop is encountering an issue. The more IDs there are, the larger the results.
<script>
var jsondata = {"45": {"id":"45","firstname":"Remy","lastname":"Janssen","age":"32"},"72":{"id":"72","firstname":"Anita","lastname":"Janssen","age":45}};
function display( jsdata ){
var htmltabel = '';
for ( var key in jsdata ){
var datanode = document.createElement("div");
htmltabel += '<div class="id">' + jsdata[key]['id'] + '</div>';
content = htmltabel;
datanode.innerHTML = content;
document.getElementById("result").appendChild(datanode);
}
}
</script>
<div class="result" id="result"></div>
<script>display(jsondata);</script>
The result shown below displays:
<div class="result" id="result">
<div>
<div class="id">45</div>
</div>
<div>
<div class="id">45</div>
<div class="id">72</div>
</div>
I am seeking the following desired output:
<div class="result">
<div class="id">45</div>
<div class="id">72</div>
</div>