vendredi 6 mars 2015

Loop through an array using each jquery


Vote count:

0




HTML



<div id="background_cycler">
<img class="active" src="" alt=""/>
<img src="" alt="" />
<img src="" alt="" />
<img src="" alt=""/>
</div>


JS



var bgImg = [
'img/bg1.jpg',
'img/bg2.jpg',
'img/bg3.jpg',
'img/bg4.jpg'
];

$("#background_cycler").each(function(index){
$(this).find('img').attr("src", bgImg[index]);
});


The above code inserted bg1.jpg into all of my images, where is my mistake? I thought I loop through the bgImg array using each()'s index?



asked 35 secs ago







Loop through an array using each jquery

Aucun commentaire:

Enregistrer un commentaire