Please help with link

Hello,

I am new to javascript, so I would need some help here [image]

As you can see below, the code is written in a way, that when there is a link, by clicking on it, the behavior is set to scrool down to the section that has certain ID.

However, I have one (or more) links (a href) on my webpage, that I do not want to inherit this behavior, but to work as an actual link - meaning redirect to different page within my website.

Any thoughts how I can achieve that, what other element do I have to write in the js?

Thank you in advance

////////////////////////////////////////////////////////
// Smooth scrooling animation

const allLinks = document.querySelectorAll("a:link");

allLinks.forEach(function (link) {
  link.addEventListener("click", function (e) {
    e.preventDefault();
    const href = link.getAttribute("href");

    // Scroll back to top
    if (href === "#")
      window.scrollTo({
        top: 0,
        behavior: "smooth",
      });

    // Scroll to other links
    if (href !== "#" && href.startsWith("#")) {
      const sectionEl = document.querySelector(href);
      sectionEl.scrollIntoView({ behavior: "smooth" });
    }
  });
});
type or paste code here

change your selector to avoid selecting the links you don’t want

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.