KedeXx KedeXx - 6 months ago 27
HTML Question

javascript write object value to div

I need to write value of name from tracks object to plTitle using loop or some function if it exists . Please help I don't wan't to do this without JavaScript but I'm not very good at it so I need your help.

tracks = [{
"track": 20,
"name": "Magus - Smith St. Basement (01/08/04)",
"length": "05:46",
"file": "SSB01_08_04_M"
}, {
"track": 21,
"name": "Beneath The Painted Eye - Smith St. Basement (06/06/03)",
"length": "13:08",
"file": "SSB06_06_03_BTPE"

$('.plItem .plTitle').each(function() {
var trackName;

for (var key in tracks) {
trackName = ''
var obj = tracks[key];
naslov =;
$(this).replaceWith('<div class="plTitle">' + trackName + '</div>');

<script src=""></script>
<div class="plwrap">
<div class="plItem">
<div class="plTitle"></div>
<div class="plItem">
<div class="plTitle"></div>

If you need additional info let me know!


You probably don't need the .each-function here. You can use .text() with a function as it's parameter here:

$('.plItem .plTitle').text(function( index ) {
  return tracks[index].name;

This will write the title of the movei from your tracks array in the respective element dependet on the elements index.