Dynamically add className/class in a element | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Dynamically add className/class in a element

I want to add a className to my li in my nav, so the user will know if they're in home, contact, or about page, I'll just a border to specify where they are in the nav.

6th Jun 2019, 10:20 AM
Shawaine
Shawaine - avatar
1 Answer
+ 2
element.classList.toggle("secondClassName");
6th Jun 2019, 10:28 AM
Gordon
Gordon - avatar