This is the JavaScript code I wrote :
var goToSecondPage= document.querySelector('.mobile');
goToSecondPage.addEventListener("click", function() {
document.location.href='productDetails.html';
})
I'm trying to use an image in an existed class on an index html page (called mobile) and make it as a clickable link image to another html file called productDetails.html
<img />in an<a>? (i.e. Do you control the HTML or not? If you do, then just add a<a>in the HTML and skip scripting entirely - that way users using keyboard-navigation can navigate, as well as middle-clicking for opening in a new tab, as well as supporting users with JS disabled, etc.