This return me object Object. how can make an array of src?
$('#mainContainerPortfolio #activateBox').click(function(){
var clickedAlt = $(this).children('img').attr('alt');
var imgs = $('#mainContainerPortfolio #projectImg[alt="'+clickedAlt+'"]');
imgs.src;
var i = [];
i.push(imgs);
console.log(i);
});
In your code,
imgsis a jQuery object, not a DOM element. As such, it does not have a.srcproperty.If you want the
.srcproperty of an image in that jQuery object, then you need to do one of the following:or, get the first DOM element from the jQuery object:
Also, there are several other errors in your code. If you want to accumulate the
srcvalue of all elements that are clicked on into an array, you could do something like this:I think there is also a problem with your selector because you can only have one element with an
id="projectImg"so there should be no reason to be using the attribute [alt=”‘+clickedAlt+'”] with it.Similarly,
'#mainContainerPortfolio #activateBox'could just be changed to'#activateBox'since there can only be one object with an id ofactivateBox.