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
It depends where your productDetails.html file is located. If it's in the root directory try
var goToSecondPage = document.querySelector('.mobile');
goToSecondPage.addEventListener("click", function() {
document.location.pathname = '/productDetails.html';
});
This will only change your path, not the entire url.