I have this list of images
<div class="item board col-sm-6 col-md-4 col-lg-4 mb-4" onclick="show()">
<a href="#" class="item-wrap fancybox">
<div class="work-info">
<h3>TITLE</h3>
<span>TEXT</span>
</div>
<img class="img-fluid" src="img/image-9.jpg" >
</a>
</div>
<div class="item maison col-sm-6 col-md-4 col-lg-4 mb-4" onclick="show()">
<a href="#" class="item-wrap fancybox">
<div class="work-info">
<h3>TITLE</h3>
<span>TEXT</span>
</div>
<img class="img-fluid" src="img/image-1.jpg" >
</a>
</div>
I would like the the the full path of the image when I click on the div
function show(){
var img = event.target.getAttribute("src");
console.log(img);
}
However when I look in the console it returns null why is that?
2
Answers
Lol, is this a homework or a test question? 😂
The problem appears to be that the
onclick
is on thediv
and not on theimg
if you updateshow
to the following:it should work