
I've included an image, and I'm looking to implement a feature where users can enlarge the image by clicking on it. Is there a way to achieve this using JavaScript?

I've included an image, and I'm looking to implement a feature where users can enlarge the image by clicking on it. Is there a way to achieve this using JavaScript?
Best answer by ahmedA
You can use the following js code:
Qualtrics.SurveyEngine.addOnReady(function () {
const quest = this;
const qc = quest.getQuestionContainer();
const images = qc.querySelectorAll("img");
const startingWidths = [];
const imageMaxWidth = "${e://Field/imageMaxWidth}" || "unset";
images.forEach((image, index) => {
startingWidths.push(image.style.width);
image.onclick = function () {
const currentState = image.style.width;
if (currentState == "unset" || currentState == "") {
image.style.width = startingWidths[index];
} else {
image.style.width = imageMaxWidth;
}
};
});
});
If you want to control the maximum size upon expansion, you can set an ED with the name imageMaxWidth to a certain pixel value (such as 200px).
Already have an account? Login
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.