Javascript in HTML editor for alternate images in question options | XM Community
Skip to main content
Question

Javascript in HTML editor for alternate images in question options

  • June 12, 2023
  • 0 replies
  • 44 views

JohannesCE
Level 6 ●●●●●●
Forum|alt.badge.img+12

Hi!

In a MC question, I have custom images for each of the 6 options.

Now I want the image to change when clicked on to an alternate image.

All the images are in the library and I have the links.

I know the script should be placed in the HTML editor of the option itself.

This is what I have:

<img src="LINK1" onclick="changeImage(this)">

<script>
function changeImage(img) {
if (img.src === "LINK1") {
img.src = "LINK2";
} else {
img.src = "LINK1";
}
}
</script>

It's not working. Why?