jquery - How do I put the proper data from this array into the place I need it to go? -


here's idea, pull color hex codes supplied sql , injected span in these list items , use hex codes set background color of span it's in. able proper information array i'm not sure how should go setting backgroundcolor rule in correct order array.

<ul id="color-hr">         <li id="hr-aqua">             <a href="javascript:"><span></span></a>             <ul>                 <li><a href="javascript:"><span>70859a</span> jetstream</a></li>                 <li><a href="javascript:"><span>4d98b5</span> periwinkle</a></li>                 <li><a href="javascript:"><span>5ecfcc</span> deep caribean</a></li>                 <li><a href="javascript:"><span>b6d8d5</span> sky</a></li>             </ul>         </li> </ul>  /** color bar **/ $("ul#color-hr > li > ul li span").each(function (data, i) {     $this = $(this);     var colorarr = $this.map(function () { return $this.text() });     var barcolor = 0;      (var = 0; < colorarr.length; i++) {         console.log(colorarr);         $(this).css('backgroundcolor', '#' + barcolor);     }  }); 

there no need loop twice.

you can change code to:

$("ul#color-hr > li > ul li span").each(function (data, i) {     $this = $(this);      $this.css('backgroundcolor', '#' + $this.text()); }); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -