1
<img id="myImg" src="https://drive.google.com/uc?export=view&amp;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&amp;id=1gsRqRNoKabIkK9z1NhioUhpFOgIKww5Q";
}
</script>

Image from the same link is loading properly. But it fails to change when using a js function

0

1 Answer 1

2

&amp; 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;.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.