I'm encountering an issue in my script where I tried to implement an event that changes the background-image of a div when a button is clicked, but it's not functioning as intended.
Below is the code snippet:
HTML
<div class="col-md-2 imageCard" style="float:left">
<img class="card-img-top"
src="https://mdbootstrap.com/img/Photos/Horizontal/City/4-col/img%20(60).jpg" alt="Card image cap">
</div>
<div class="card-body">
<blockquote class="blockquote mb-0">
<p id="quoteSample">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p>
<footer class="blockquote-footer" id="quoteAuthorSample">Someone famous in </footer>
</blockquote>
</div>
JS
$('.imageCard').click(function(){
var imageSRC = ($(this).children('img').attr('src'));
console.log(imageSRC)
$('.card-body').css("background-image", "url(" + imageSRC + ")")
})
The output from console.log shows: