0

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

Debug Diva
  • 26,058
  • 13
  • 70
  • 123

1 Answers1

1

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.

Marian
  • 44
  • 1
  • 7