I have a close button which is used to get an image src positioned just above it:
<div class="col">
<img class="img-thumbnail" src="/path/to/image2.gif">
<br>
<span class="img-remove">x</span>
</div>
jQuery:
$(document).on('click', '.img-remove', function () {
let _self = this;
let img_src = $(this).closest('.img-thumbnail').attr("src");
console.log('img_src', img_src);
});
However instead of src value I get this in console:
img_src undefined
What is wrong here and how can I fix it?
$(this).closest('.col').find('.img-thumbnail').attr('src')closestlook upwardthisdiv?