Hi guys, I have an Elementor multiple Gallery. A few of the images have to be clickable and to redirect to a specific link. I tried to do it whit the following code. My goal was to identify the image by the default url of the media and then say to it, if you have this specific link, redirect to that link:
document.addEventListener(‘DOMContentLoaded’, function () {
​
var links = {
/\*url of the image\*/ “[https://arc-architecture.ch/wp-content/uploads/2023/05/Appartements-PPE-Reconvilier-e1686143826933.jpg]”:/\*link where this specific image should send\*/ ‘[https://arc-architecture.ch/appartement-ppe-a-reconvilier/]’,
“[https://arc-architecture.ch/wp-content/uploads/2023/05/autreImage.jpg]”: ‘[https://example.com/link2]’,
};
​
var images = document.querySelectorAll(‘.e-gallery-item img’);
images.forEach(function (img) {
var src = img.getAttribute(‘src’);
var link = links\[src\];
if (link && link.length > 4) {
img.parentNode.style.cursor = “pointer”;
img.parentNode.addEventListener(‘click’, function () {
window.location = link;
});
}
});
});
​
Thanks a lot guys !
[ad_2]