I’m using Barba.js for handling page transitions in my website. I have a navigation menu that opens when clicking on a div with the class nav-btn. Everything works perfectly when the page is loaded for the first time, but after transitioning to another page using Barba.js, the click event listener for the navigation menu button no longer works till refresh the page.
Here’s the relevant part of my code:
function navOpener() {
let navbtn = document.querySelector(".nav-btn");
if (navbtn != null) {
console.log("Navopener running...");
console.log(navbtn);
navbtn.addEventListener("click", function () {
console.log("nav opener clicked");
// Other logic here...
});
}
}
When I check the console, I see the message “Navopener running…” and navbtn element after the transition so i am sure navbtn is ok, but the click event listener doesn’t trigger anymore, and the console.log(“nav opener clicked”) never shows up. I am running all the functions beforeEnter. And as i said when refresh the page everything works perfectly.