html - javascript function to color using color array and for loop -
i have created function create html elements json object. have created array of 3 different colors , want loop through array, using each color @ time color part of sentence formed html elements. there 2 roles in particular object (ie. singlejsonobj.roles.length equal 2). trying print first html element "darksalmon" , next 1 "forestgreen" loops. is, however, printing both role names "darksalmon". please see code below. missing?
function createhtmlelementsforrolenumbers (singlejsonobj, xml) { // result returned var finalxml; var colorarr = ["darksalmon", "forestgreen", "brown"] // block of html elements created var htmlforrolenumbers = ""; ( var i=0; i< singlejsonobj.roles.length; i++) { // each time creating 1 html element. // e.g. if length above 2, create 2 h4 elements. htmlforrolenumbers = htmlforrolenumbers + "<h4><br> - a(n) <font color='" + colorarr[i] + "'>" + singlejsonobj.roles[i].name + "</font><br></h4>"; } finalxml = string(xml).replace(/role_numbers/g,htmlforrolenumbers) // output return finalxml; }
Comments
Post a Comment