Answer the question
In order to leave comments, you need to log in
Why doesn't the src of the image change on click?
<img class="myImg" src="img/main_center.png">
<button onclick="myFunction()">Try it</button>
function myFunction() {
document.querySelector(".myImg").src = "hackanm.gif";
}
Answer the question
In order to leave comments, you need to log in
If jquery is included, try this:
If jquery is not included, then like this:
$('.myImg').attr('src','hackanm.gif');
document.querySelector(".myImg").setAttribute('src', 'hackanm.gif');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question