April 27, 2024

MoDCore

Welcome to the core

Small image in survey, click to enlarge

This code will add a small image to survey page and will enlarge the image if the user clicks on it.

HTML in survey question


Style script in the instruction node –

JavaScript node –

// Get the modal
var modal = document.getElementById(‘myModal’);

// Get the image and insert it inside the modal – use its “alt” text as a caption
var img = document.getElementById(‘myImg’);
var modalImg = document.getElementById(“img01”);
var captionText = document.getElementById(“caption”);
img.onclick = function(){
modal.style.display = “block”;
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}

// Get the element that closes the modal
var span = document.getElementsByClassName(“close”)[0];

// When the user clicks on (x), close the modal
span.onclick = function() {
modal.style.display = “none”;
}

Copyright © All rights reserved. | Newsphere by AF themes.