I'm trying to make a simple gallery with 4 images.
I wrote a pice of code but the result is always undefined
.
What I want is to show by default the first picture in div with class little
This is HTML code :
<img class="imageToShow" />
<div class="little">
<img class="imageNotToShow" src="../Images/gallery1.jpg" />
<img class="imageNotToShow" src="../Images/gallery2.jpg" />
<img class="imageNotToShow" src="../Images/gallery3.jpg" />
<img class="imageNotToShow" src="../Images/gallery4.jpg" />
</div>
This is the js code :
var firstImageSrc;
firstImageSrc = $('.imageNotToShow').first().attr("src");
alert(firstImageSRC);
$('.ImageToShow').attr("src", firstImageSrc);
` tag (e.g., where it should be), it should work fine. (You'll also get people telling you to put it in a `ready` callback, but that's unnecessary if the script tag is in the right place.)
– T.J. Crowder Feb 08 '18 at 12:43and it works fine for me thank you again
– Karam Haj Feb 08 '18 at 13:53