I've tried to setup an array, but when i use console.log(array_name)
, it prints the number of the counter (x), instead of printing the path of the image.
The undefined presents itself once I tried to use console.log(img[x])
to check if the content of the variable, it's the source of the image.
But since img doesn't work either, I don't have any clue of what is going on.
$(window).on('load', function(){
var x = 0;
var img = [];
$(".gallery_img").each(function(img){
var image = new Image();
image.src = $(this).attr("src");
x = x + 1;
img[x] = image.src;
console.log(img);
console.log($(this).attr("src"));
I'm pretty new to jquery and javascript, so I'd be very grateful for some specific explanation and not just solution. I hope I've been specific enough, and not a duplicate