I am new to jQuery. I am trying to get image src and replace the src. I can get the image using the function mentioned below but i cannot get the src.
<div class="class1">
<a href="Link1"><img src="//abc.com/1.jpg"/></a>
<a href="Link2"><img src="//abc.com/2.jpg"/></a>
<a href="Link3"><img src="//abc.com/3.jpg"/></a>
<a href="Link4"><img src="//abc.com/4.jpg"/></a>
.
.
.
<a href="Linkn"><img src="//abc.com/n.jpg"/></a>
</div>
This function doesn't work but this is what i need to do. I would like to get the src and replace the .jpg at the end with -xyz.jpg for all the images.
'galleryImg': $(this).children('img') return the image but when i add .attr('src'), it stops working
function () {
var $gallery = $('.class1 a');
return $gallery.map(function () {
return {
'galleryLink': $(this).attr('href'),
'galleryImg': $(this).children('img').attr('src').replace('.jpg','-xyz.jpg')
};
});
}