javascript - jquery - append Icons generated by for loop into list items anchor -


i grateful guidance or solution!

from array of class names, i'm generating icon sets using loop:

// icon array var iconsarray = ['fa-search','fa-toggle-up','fa-link'];  var iconsarraylength = iconsarray.length;      // loop through array     (var = 0; < iconsarraylength; i++) {          // result         console.log('<i class="fa' + ' ' + iconsarray[i] + '"></i>');      } 

i have navigation element. list has same number of items id:

<nav>      <ul id="nav">          <li><a href="">link 1</a></li>         <li><a href="">link 2</a></li>         <li><a href="">link 3</a></li>      </ul>  </nav> 

q. how append / prepend returned icon sets correct nav item?

to clear, first array value intended first navigation item , on.

i'm sure there's out there answer question, mighty g doesn't seem want serve me!

thanks in advance.

in response comment...

the resulting list this:

<nav>      <ul id="nav">          <li><a href=""><i class="fa fa-search"></i>link 1</a></li>         <li><a href=""><i class="fa fa-toggle-up"></i>link 2</a></li>         <li><a href=""><i class="fa fa-link"></i>link 3</a></li>      </ul>  </nav> 

you don't need loop

$('#nav li').each(function(i) {     $(this).append('<i class="fa' + ' ' + iconsarray[i] + '"></i>') }) 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -