T
T
Theory Theory2021-06-08 18:04:17
JavaScript
Theory Theory, 2021-06-08 18:04:17

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";
}


More precisely, in the html document, src changes, but the picture is the same

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lev Zabudkin, 2021-06-08
@zabudkin

https://instructobit.com/tutorial/119/Force-an-ima...

C
Carlyndow Marlifi, 2021-06-08
@petushok55

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 question

Ask a Question

731 491 924 answers to any question