Reputation: 81
<img id="myImg" src="https://drive.google.com/uc?export=view&id=1gsRqRNoKabIkK9z1NhioUhpFOgIKww5Q" width="107" height="98">
<button onclick="change_image()">Change Image</button>
<script>
function change_image() {
document.getElementById("myImg").src = "https://drive.google.com/uc?export=view&id=1gsRqRNoKabIkK9z1NhioUhpFOgIKww5Q";
}
</script>
Image from the same link is loading properly. But it fails to change when using a js function
Upvotes: 1
Views: 51
Reputation: 943561
&
is how you represent a &
character in HTML.
It isn't how you represent one in JavaScript (not even JS in a <script>
element in an HTML document as <script>
elements are defined so that normal HTML parsing rules (where &
would switch to the character reference state) are suspended).
The URL is getting a 400 error.
In the JS use only &
without the amp;
.
Upvotes: 2