I have a grid of 2 rows and 3 columns and I want a different image in each card, also the images should be different depending if the user enters from different menus.
I've tried using a for loop to select different images but only selects the first or the las ones.
$("img").attr('src', function() {
for (var i = 0; i < this.length; i++) {
return "media/" + currentId + i + ".jpg";
i++;
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- This is 1 card out of 6 -->
<div class="card">
<div class="card-image waves-effect waves-block waves-light">
<img class="activator">
</div>
<div class="card-content">
<span class="card-title activator"></span>
</div>
<div class="card-action">
<span class="link">Lorem impsum</span>
</div>
<div class="card-reveal">
<span class="card-title"><i class="material-icons right">close</i></span>
<p>Lorem impsum</p>
</div>
</div>
As I've described earlier in the post, the output should be 6 different images and it's just 6 equal images.
currentIda reference to?var currentId = this.idIt's insidedocument.ready()and I've used it several times during the code. I've made it a variable because I was having some trouble making it work.