Add Remove Active Class Based On URL Using Javascript | No jQuery

preview_player
Показать описание
Enroll My Course : Next Level CSS Animation and Hover Effects
------------------
Join Our Channel Membership And Get Source Code Everyday
------------------
Please LIKE our Facebook page for daily updates...
Рекомендации по теме
Комментарии
Автор

Awesome tutorial and so precise under 4mins, You need not know how many hrs i have been trying to do this. Thank you

jonathanoyekanmi
Автор

If you are experiencing "unexpected identifier" at the for-loop, simply delete the "let" and it will work. The correct code should be:
for(i = 0; i<menuLength; i++){
if(menuItem[i].href === currentLocation){
menuItem[i].className= "active";
}
}

You are welcome.

justinleong
Автор

Nice sir Great work Ager aap bol kr karate to or aache se smajh me aata but ye bhi smajh gye

alphavisions
Автор

Awesome tutorial. It solved my problem now. Thank you so much. 😍😍😍😍😍😍😍

thiinh
Автор

Saved my life. Well a few days of it anyway.

joshuaheathcote
Автор

Thank you so much!!!! I spent many hours to make this work

LyriaTempest
Автор

Total vanilla js, im starting to have feelings for yoiu

FreddyAmini
Автор

I hope not too late, 7 seconds have passed

alikubatbaev
Автор

So for this to work the page has to reload each time?.. what if its a section on the same page? Like href = #home.
Href = #about.

silentvoice
Автор

But if the page is reloaded the active menu dissapears, How to resolve that scenario?

lemueljohnerispe
Автор

Hello, thank you for your tutorial. Btw, how to deal with index.html link when the address automatically remove the "index.html" part?

universalworthy
Автор

If I change a to div class, why it cannot remove active class?

Hawiyah_galery
Автор

thank for sharing really enjoy with this video :)

honglysrou
Автор

sub pages py click ho aur parent active ho iski koi js wagera?

arslmirza
Автор

Thank you so much it works in a great way.

bacanalienigena
Автор

If I have many hrefs inside my document? I want to target a certain section but I have href all throughout my document pls help

inigozepeda
Автор

I have the navbar in a separate file and on each page i call this file with php code "require". How can I make this work in my case?

ardeleangavril-liviu
Автор

If we have a drop-down in Services will this code work?

sadanandasherigara
Автор

If I click on the submenu it will be the active menu, how do I do this?

Beautiful.Nature.