i have this express app built with nodejs and mongoDB my event listeners linked to this are acting wierd.
This is my main.js file
const threemonth=document.getElementById("threemonth");
const sixmonth=document.getElementById("sixmonth");
const onemonth=document.getElementById("onemonth");
const buy1=document.getElementById("buy1");
const buy3=document.getElementById("buy3");
const buy6=document.getElementById("buy6");
const test=document.getElementById("test");
threemonth.addEventListener("click",function(){
buy3.classList.remove("displaymonth");
buy1.classList.add("displaymonth");
buy6.classList.add("displaymonth");
})
sixmonth.addEventListener("click",function(){
buy6.classList.remove("displaymonth");
buy3.classList.add("displaymonth");
buy1.classList.add("displaymonth");
})
onemonth.addEventListener("click",function(){
buy1.classList.remove("displaymonth");
buy6.classList.add("displaymonth");
buy3.classList.add("displaymonth");
})
test.addEventListener("click",function(){
alert("you have clicked");
})
The problem is the event listener for “test” oly works when it is defined on the top,before all other listeners .But then the listeners below the “test” listeners doesnt work.If i define “test” listener at the bottom .All other listeners work except “test” listeners.What is the solution here please help me out
and to mention the only event listener which is in a separate,different page is “test” all other listeners are in the same page