Click here to Skip to main content
15,663,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i click on navigation link , i want to add a class. But after event is fired , class seems to be added only for a second and then it is not there.

What I have tried:

<pre>"use strict";
const navItemLink = document.querySelectorAll(".nav-item-link");
const header = document.querySelector(".header");

navItemLink.forEach((items) => {
	items.addEventListener("click", function () {
		console.log(items, this);
Chris Copeland 2-Feb-23 6:37am    
This seems like a duplicate/extension of this question you already raised[^]. You haven't particularly made it clear what it is you're trying to accomplish.
Member 15627495 3-Feb-23 8:05am    
'a' link do two things .. it leads you to another page, or to the described anchor.
if you don't want another page by click, you have to let 'blank' the Href="" attribute.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900