0

I have created two HTML pages. But I am not getting element of second HTML page in JavaScript event listener.

My goal : Whenever anybody click on any product its picture, title and description replace with the image, title and description of single product page. first HTML page second HTML page

product.forEach(function (products) {
  products.addEventListener("click", function (curr) {
    location.href = "http://127.0.0.1:5500/single.html";

    // element of first html page
    let productImg = curr.currentTarget.firstElementChild.firstElementChild;
    // element of second html page
    let img = document.querySelector(".sp-img");
  });
});
Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
  • Your snippet is incomplete; what is `product`? – mykaf Jul 05 '22 at 16:31
  • 4
    You are not going to be able to load a new page and run JavaScript after you do that. When you set the location, the page navigates away, code after that is gone. – epascarello Jul 05 '22 at 16:31
  • 1
    **location.href** redirects the user stopping anything under it from happening – imvain2 Jul 05 '22 at 16:33
  • 2
    You cannot access any element "on the second page" from the first page's javascript. Maybe you mis-spoke and meant popup window. In that case -- it might not be loaded yet. – patrick Jul 05 '22 at 16:35

0 Answers0