79083250

Date: 2024-10-13 13:34:03
Score: 0.5
Natty:
Report link

There's no real problem in the HTML documents, but instead the script file.

The problem is that JavaScript files load from top to bottom of the file. On the about page, it can't find a button going to the about button, so it provides an error in the console and stops loading the rest.

You can fix this by moving the order, which I don't recommend that, because it will still result in an error although it will work.

What I would do is make separate JavaScript files, I would like "a" tags (hyperlinks), or I would check to see if there was a button before adding an event listener to it, like this:

if (document.querySelector("#about")) {
  document.querySelector("#about").addEventListener("click", function () {
    window.location.href = "about_me.html";
  });
}

if (document.querySelector("#about")) {
  document.querySelector("#contact").addEventListener("click", function () {
    window.location.href = "contact_me.html";
  });
}

if (document.querySelector("#home")) {
  document.querySelector("#home").addEventListener("click", function () {
    window.location.href = "home.html";
  });
}

I've been trying to post this for like 20 minutes, but I just posted on another question so I had to wait 30 minutes.

I just saw your response, and it works but the only problem is it runs for every button on the page, which is possible to make it lag if there's a lot of interactivity.

Reasons:
  • Blacklisted phrase (1): another question
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Grant