Тёмный

Active Nav Link Indicator with Vanilla Javascript 

Coding in Public
Подписаться 46 тыс.
Просмотров 115 тыс.
50% 1

Apply a class to the navigation link for the current page with a few lines of Javascript.
Here's the JS: codepen.io/Coding-in-Public/p...

Хобби

Опубликовано:

 

25 июн 2021

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 191   
@chooseyourtool
@chooseyourtool 4 месяца назад
FINALLY I found your video. I was so much looking for this. But other videos I found were so overcomplicated and missing the point. Thank you, very well done.
@gabrielfono844
@gabrielfono844 Год назад
I love the way that you explain things as software engineer, we all love simplicity. thanks for providing such high value to the community
@CodinginPublic
@CodinginPublic Год назад
That’s very kind. Thanks for saying something!
@armandoWebDev
@armandoWebDev Год назад
The step by step explanation was really great! Thank you
@CodinginPublic
@CodinginPublic Год назад
Great! Thanks for saying something!
@neelamchaubey28
@neelamchaubey28 2 года назад
Such an amazing and informative video! Thanks so much. I landed up on this channel through your videos on Shaun's channel. Glad I found it!
@CodinginPublic
@CodinginPublic 2 года назад
Thanks so much. Glad you enjoyed it!
@siddharththapa4672
@siddharththapa4672 Год назад
this was the most simplest and on point tutorial on this topic.....much love from INDIA
@CodinginPublic
@CodinginPublic Год назад
So glad you enjoyed it!
@princemalongo9303
@princemalongo9303 3 месяца назад
Your code is see,simple to understand, and the presentation itself is so sweet.
@CodinginPublic
@CodinginPublic 3 месяца назад
Glad you liked it
@Pookamensch
@Pookamensch 8 месяцев назад
I saw others solutions, but yours is the most simple and the most well explained of all! Thanks!!!
@CodinginPublic
@CodinginPublic 8 месяцев назад
So glad it was a help!
@akshayshinde2403
@akshayshinde2403 2 года назад
basically we are highlighting that navlink to which it belongs, its that simple. I will use this forever.
@CodinginPublic
@CodinginPublic 2 года назад
Glad it was a help!
@petersonokereke1634
@petersonokereke1634 2 года назад
Thanks so much for this amazing video. JavaScript has been after my life these past few weeks. This solved my problem
@CodinginPublic
@CodinginPublic 2 года назад
You’re welcome! Glad it was a help! I’ve got an update coming out soon, too!
@leonardmbibi8013
@leonardmbibi8013 Год назад
I found out I could use activePage = window.location.href and use strict equality operator to campare it to each "href" with the same results as yours. Your video just introduced me to Browser Object Model. Thanks a lot.
@CodinginPublic
@CodinginPublic Год назад
Awesome! You're welcome. I also did a follow-up video that should help, too! ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-HpjW9eaFLIg.html
@sarvesh6785
@sarvesh6785 Год назад
Thank you very much, sir! I was trying to find a solution for three hours, but none of them worked. Finally, this worked perfectly.
@CodinginPublic
@CodinginPublic Год назад
Wonderful! Thanks for sharing!
@the-beauty-of-creativity2083
@the-beauty-of-creativity2083 2 года назад
Thank god I found this video. I lost sometime looking for this solution. Thanks Bro!
@CodinginPublic
@CodinginPublic 2 года назад
Awesome! So glad it was a help! Thanks for saying something!
@darklordpassy5361
@darklordpassy5361 2 месяца назад
You explained it so well and simple. Thank you!
@CodinginPublic
@CodinginPublic 2 месяца назад
Glad it was helpful!
@okaniedavis3551
@okaniedavis3551 Год назад
Perfect, exactly what I needed. Thank you!
@CodinginPublic
@CodinginPublic Год назад
You’re welcome!
@claudiofernandes6430
@claudiofernandes6430 Год назад
Congratulations. This is the best solution that I found in the RU-vid. Thank you very much.
@maisha-safari
@maisha-safari 3 месяца назад
You are an excellent teacher, thank you.
@CodinginPublic
@CodinginPublic 3 месяца назад
You're very welcome!
@kllokoq
@kllokoq Год назад
This is probably the easiest way I've seen of adding an active class. Instead of going and removing the class from the previously selected link, it skips all that non-sense.Lovely!
@CodinginPublic
@CodinginPublic Год назад
Glad it was a help!
@muhammedibrahem5100
@muhammedibrahem5100 Год назад
He doesn't have to remove the class because the page does refresh on each click, so the class is being removed already once he clicks any of the buttons, The solution u are saying is for the same page buttons without any refreshes, at this moment u gotta remove the class then add it to the new clicked button
@pikkuk5693
@pikkuk5693 2 года назад
it is so awesome and easy to understand which anyone never told me this video deserve more likes
@CodinginPublic
@CodinginPublic 2 года назад
Glad it was a help! Thanks for saying something!
@yanakochubynska5568
@yanakochubynska5568 Год назад
This video really helped a lot, thank you!
@CodinginPublic
@CodinginPublic Год назад
Glad it helped!
@ingridsantos1143
@ingridsantos1143 Год назад
Thanks so much. This tutorial was really helpful and well explained.
@CodinginPublic
@CodinginPublic Год назад
Wonderful! Thanks for saying something!
@choanlpoto
@choanlpoto 2 года назад
Thanks a lot. I thought having an active link status was super easy like 1 css pseudo elements lol. . I found no good tuto on how to do it. Nothing worked until yours. Awsome Channel subbed. Thx.
@CodinginPublic
@CodinginPublic 2 года назад
So glad it was a help! Thanks for saying something!
@Amalnajah-b2v
@Amalnajah-b2v 11 месяцев назад
Thank youuuu I struggled a loot with this so thank you 🎉🎉
@CodinginPublic
@CodinginPublic 11 месяцев назад
Happy to help!
@rajkiranchaudhary8769
@rajkiranchaudhary8769 2 года назад
Thanks a lot for this amazing content.
@CodinginPublic
@CodinginPublic 2 года назад
Glad it was a help!
@RJ-gj1zv
@RJ-gj1zv 2 года назад
Thanks, man. absolutely brilliant
@CodinginPublic
@CodinginPublic 2 года назад
Glad it was a help!
@hexd7439
@hexd7439 2 года назад
Thanks a lot! This tutorial helped me.
@CodinginPublic
@CodinginPublic 2 года назад
Awesome! Thanks for saying something!
@makidelavega3079
@makidelavega3079 2 года назад
Thanks for this video ,it helped me a lot.
@CodinginPublic
@CodinginPublic 2 года назад
Wonderful! Thanks for saying something!
@cheesychains
@cheesychains 2 года назад
This saved me, thank you so much!
@CodinginPublic
@CodinginPublic 2 года назад
I'm so glad!
@connorbyram3649
@connorbyram3649 Год назад
This is a wonderful solution. I was having an issues where ALL of my nav links had the active class added to them- because I am utilizing a directory. To skirt this I came up with this: By directly/strictly comparing the window href and the link href, there is only one possible match. document.querySelectorAll('.nav-links a').forEach(link => { if(link.href === window.location.href) { link.classList.add('active'); } });
@CodinginPublic
@CodinginPublic Год назад
Great! Yeah, I updated this video here to work the way it SHOULD have worked. :) ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-HpjW9eaFLIg.html
@ylitandi
@ylitandi Год назад
Thank you very much ! So the code is : const activePage = window.location.pathname; const navLinks = document.querySelectorAll('.nav-links a').forEach(link => { if(link.href === window.location.href){ link.classList.add('active'); console.log(link); } }); ??? 🙂
@connorbyram3649
@connorbyram3649 Год назад
@@ylitandi I will have to look back at my code. But that should work. Have you demoed it? Also, there's no need for that console.log(link).
@cesarpacheco9155
@cesarpacheco9155 Год назад
Profesor muchas gracias por este video me sirvio de mucho saludos desde Colombia
@CodinginPublic
@CodinginPublic Год назад
🙏
@efieugenia
@efieugenia Год назад
What a wonderful tutorial
@CodinginPublic
@CodinginPublic Год назад
So glad you enjoyed it!!
@dadwalkanishka9210
@dadwalkanishka9210 9 месяцев назад
thanks for the code it was helpful for me
@CodinginPublic
@CodinginPublic 9 месяцев назад
So glad! Thanks for taking the time to say something!
@mohamed_younes77
@mohamed_younes77 Год назад
thx man very simlpe and clear
@CodinginPublic
@CodinginPublic Год назад
You're welcome!
@kamaboko1
@kamaboko1 11 месяцев назад
Superb explanation.
@CodinginPublic
@CodinginPublic 11 месяцев назад
Glad you liked it
@chriswesleypierre1440
@chriswesleypierre1440 7 месяцев назад
precise, quick, useful
@CodinginPublic
@CodinginPublic 7 месяцев назад
Glad you found it helpful!
@ak-yo6pf
@ak-yo6pf Год назад
you are a g thanks for that!
@juanalmonte1642
@juanalmonte1642 2 года назад
Good and easy to understand
@CodinginPublic
@CodinginPublic 2 года назад
Glad it was a help!
@wtfmomentninenine
@wtfmomentninenine 11 месяцев назад
thank you, sir
@RJ-6615
@RJ-6615 3 года назад
Very helpful!
@CodinginPublic
@CodinginPublic 3 года назад
Good to hear! Thanks for saying something!
@codingislife6387
@codingislife6387 Год назад
thanks Sir Jee. It Very Help Full Thanks .
@CodinginPublic
@CodinginPublic Год назад
Glad it was a help!
@Steve-rx4sw
@Steve-rx4sw 2 года назад
good work bro. thanks
@CodinginPublic
@CodinginPublic 2 года назад
glad it was a help! Thanks for saying something!
@sbf.2189
@sbf.2189 Год назад
Thank you so much man
@CodinginPublic
@CodinginPublic Год назад
So glad it was a help!
@asidermakriver
@asidermakriver 2 года назад
Thank you!
@CodinginPublic
@CodinginPublic 2 года назад
You’re welcome! Thanks for saying something!
@ricardodelacrvz1400
@ricardodelacrvz1400 Год назад
thank you for this tuto. I actually had to use window.location.href instead of pathname since Im using different slugs to the same pathname between product categorys in php.
@CodinginPublic
@CodinginPublic Год назад
Yes! I ended up updating the video later to something much better here :) ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-HpjW9eaFLIg.html
@salmajahan5834
@salmajahan5834 3 месяца назад
Thank you so much, super like
@CodinginPublic
@CodinginPublic 3 месяца назад
Glad you enjoyed it!
@ankitmakwana3141
@ankitmakwana3141 2 года назад
awsm great!!
@nigelpallatt
@nigelpallatt 2 года назад
BRILLIANT THANK YOU!
@CodinginPublic
@CodinginPublic 2 года назад
Awesome! Glad you liked it!
@nigelpallatt
@nigelpallatt 2 года назад
@@CodinginPublic Sort of had a typo on the first try, but it works lovely now, I'll be using this from now on all my sites, Thank you again and great work!
@CodinginPublic
@CodinginPublic 2 года назад
👀
@sokcheahong1468
@sokcheahong1468 Год назад
really helpful
@CodinginPublic
@CodinginPublic Год назад
Thanks for saying something. Glad it was a help!
@RuiOut8
@RuiOut8 2 года назад
Thank you! This is really helpful! Does this concept work for one page websites where the Nav links to IDs within the same HTML file?
@CodinginPublic
@CodinginPublic 2 года назад
You’re welcome! For IDs on a one-page site it’s even easier! You can use the :target pseudo selector to apply styles to the nav links using only CSS!
@RuiOut8
@RuiOut8 2 года назад
@@CodinginPublic awesome! Thank you very much!
@footballcorner6
@footballcorner6 9 месяцев назад
Thank you so much
@CodinginPublic
@CodinginPublic 9 месяцев назад
Glad it was a help!
@lordilhamgod4417
@lordilhamgod4417 Год назад
Works well!! DANKEEE
@CodinginPublic
@CodinginPublic Год назад
You’re welcome!
@itszeynepk
@itszeynepk 2 года назад
thank you so much
@CodinginPublic
@CodinginPublic 2 года назад
You’re welcome! Thanks for saying something!
@Ganito55
@Ganito55 Год назад
Hi!, amazing stuff! Is it easy to stop page refresh? Maybe using ajax/fetch? Many thanks
@CodinginPublic
@CodinginPublic Год назад
I'm not sure I understand what you mean?
@moneyfr
@moneyfr 2 года назад
Do you know how make dynamic navbar (all forder page show into navebare) for each li maybe?
@CodinginPublic
@CodinginPublic 2 года назад
I’m not sure I understand? Here is a video I did on navbars recently though. Hopefully that helps. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-63sxOYm9GwY.html
@Dontmesswithmeplease
@Dontmesswithmeplease 2 года назад
Super
@alphamx13
@alphamx13 9 месяцев назад
Great! Just one question... how can you also add the active class to the menu section if you scroll down or up the page ? Thank U!
@CodinginPublic
@CodinginPublic 8 месяцев назад
I’ve done a tutorial like this a long time ago, but not finding it right now. Sorry!
@brucewernick6542
@brucewernick6542 4 месяца назад
You put a forward slash in front of the anchor links. So, when running in a browser, this makes it try to find the file in the root directory. I removed this forward slash and it works in browser and the local web server.
@usef439
@usef439 2 года назад
Thanks!
@CodinginPublic
@CodinginPublic 2 года назад
You’re welcome! Thanks for saying something!
@adrian20065
@adrian20065 2 года назад
Thanks a lot for this tutorial! I recently came across you channel and subscribed. How can you keep the parent active is it has children? Thanks again!
@CodinginPublic
@CodinginPublic 2 года назад
Thanks so much! Just to make sure I understand, are you wanting to keep the parent active if it has a submenu?
@adrian20065
@adrian20065 2 года назад
@@CodinginPublic Yes, I want to keep the parent active if it has a submenu. Thanks for the quick reply.
@CodinginPublic
@CodinginPublic 2 года назад
Just saw today that RU-vid blocked your reply and never notified me. Sorry! You still need help?
@adrian20065
@adrian20065 2 года назад
@@CodinginPublic Yes, I still like to know how to keep the parent menu item active when the child menu item is selected. Thank you.
@jivara5523
@jivara5523 6 месяцев назад
ty very much
@CodinginPublic
@CodinginPublic 6 месяцев назад
You're welcome!
@luciaholubova7504
@luciaholubova7504 Год назад
Hi How do I get the content stay on the page, instead of taking me to new page with using anchor?
@CodinginPublic
@CodinginPublic Год назад
Anchor links can take you to any element on the page with an ID. It takes two steps: 1. Create a page element with an ID. Like this… Hi, I’m a link! 2. Point the href of an anchor tag to that ID. like this… Click to jump (Note the #) Whenever you click the link, it’ll jump to that ID on the page.
@yofi2614
@yofi2614 2 года назад
Great tutorial, so clear and plesant to here, thank! One quick question, let say you click the home button and it gets the active class, But what remove this class in next rounds? Logically it should have left this class on every button that had been clicked so eventually if you click all the buttons all of them will be black
@CodinginPublic
@CodinginPublic 2 года назад
Glad it was a help! Because you’re applying the class using client-side JavaScript, the class will be removed each time you change to a different page. Once you arrive on the next page, you can apply the class again for the current page you’re on at that time. Does that make sense? I’ve actually updated my process for applying active links here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-HpjW9eaFLIg.html
@yofi2614
@yofi2614 2 года назад
@@CodinginPublic totally makes sense cause i haven't learnt client side js yet, but i will look up at the link you gave, so much thankful for the quick respond! Subscribed!
@CodinginPublic
@CodinginPublic 2 года назад
You’re welcome! Client-side JavaScript means JavaScript that the site visitor’s browser runs (so like the JavaScript we wrote in this video). In other words, it’s only applied once the page loads. Hopefully that helps some. Thanks for the sub!
@yofi2614
@yofi2614 2 года назад
@@CodinginPublic thanks!
@pbt4820
@pbt4820 5 месяцев назад
thank you for the vid. I am trying to have the viewed page underlined instead of highlight with black blocks. is that possible with this method?
@CodinginPublic
@CodinginPublic 5 месяцев назад
Sure! Just switch up the CSS. I'd make it have a transparent underline (border-bottom) when not selected and then just the color you want when it is selected.
@andrewlawton2487
@andrewlawton2487 2 года назад
Thank you very much for the video. I implemented your code accordingly and experiencing one issue I'd greatly appreciate your assistance with. When I click the nav home link all the links become active and I'm not sure why? Looking at the console.log it shows all path names not just the home page index.html. Thank you in advance for your help.
@CodinginPublic
@CodinginPublic 2 года назад
Glad it was a help! Hmm…I’m guessing you’re in a directory? Like…www.website/temp/ If that’s the case, all links in your nav links will include the directory (“temp” in this example). Go to your home page and console.log(window.location.pathname) Assuming that’s the problem it will include the directory and you can remove it by using the substring method. If that’s not clear or doesn’t work, feel free to drop a link to a GitHub or something or DM on Twitter at cpenned.
@andrewlawton2487
@andrewlawton2487 2 года назад
@@CodinginPublic Thank you for your quick reply Chris. I will let you know if your suggestion works. Thanks again!
@behold_a_son
@behold_a_son 2 года назад
Is there a need to synchronize the desktop navbar active states to mobile navbar active states if both the styles are different? Meaning If I click the mobile nav link. The same link in the desktop nav should be active and vice versa. I spent a lot of time and accomplished this in a practice problem but I'm worried that it was not worth the effort.
@CodinginPublic
@CodinginPublic 2 года назад
Thanks for the comment. Hmm…assuming you have the desktop/mobile nav bar set to display:none whenever it's not showing, it shouldn't matter. If they're both rendered and you set them both to active, that would cause some accessibility issues, I believe. FWIW, I usually only have one nav that I just style differently depending on viewport width (example: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-63sxOYm9GwY.html), so I usually don't run into your question.
@behold_a_son
@behold_a_son 2 года назад
@@CodinginPublic Thank you, that's insightful!
@RohitSharma-wq4ok
@RohitSharma-wq4ok Год назад
Sir on home page it apply to all links active class and on console it show active 5 link in only on home page
@CodinginPublic
@CodinginPublic Год назад
On some sites that's the case. Did an update that fixes that an a few other issues :) ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-HpjW9eaFLIg.html
@Rahul-ur6xz
@Rahul-ur6xz Год назад
What Editor Do You Use ?
@CodinginPublic
@CodinginPublic Год назад
I think I was using Nova in this video, but I use VSCode now.
@tmm476
@tmm476 8 дней назад
u da mann
@CodinginPublic
@CodinginPublic 5 дней назад
glad you found it helpful!
@suresranathunga
@suresranathunga Год назад
💙💙
@Dontmesswithmeplease
@Dontmesswithmeplease 2 года назад
YOu are king, :) . Alexander the great
@CodinginPublic
@CodinginPublic 2 года назад
lol glad you liked it
@AlThePal78
@AlThePal78 Год назад
i wish you had the css for this too on your code pen but still n awesome vid
@CodinginPublic
@CodinginPublic Год назад
Yeah, sorry 😞. This was before I was saving all code from my videos I think
@AlThePal78
@AlThePal78 Год назад
@@CodinginPublic that is okay I am stealing this and making my own video lol I will add a secondary class called link so I can add an underline and change the backgrouind color etc.. thanks so much :)
@sal-so2rw
@sal-so2rw Год назад
What's happening I can't see things clearly
@CodinginPublic
@CodinginPublic Год назад
It's highlighting the active page link in the nav bar. Is that what you're asking?
@okaniedavis3551
@okaniedavis3551 Год назад
Is there a way to do this for sub links in a side panel inside a parent link, like a tree, To make the parent link remain open displaying child/sub links? Is there a video that can help me?
@CodinginPublic
@CodinginPublic Год назад
There is a way to do this; not sure about a video? I haven't done one. Sorry! :)
@okaniedavis3551
@okaniedavis3551 Год назад
@@CodinginPublic After all, this video was also enough to achieve what I wanted with my parent and child links. Thank you 👌
@kimkorngmao
@kimkorngmao 2 года назад
hi, My problem is when in the url doesn't have "index.html", It active for all the link. what should is do?
@CodinginPublic
@CodinginPublic 2 года назад
Yes, I’ve done a more recent tutorial on the same topic to address this problem. Hope it helps! ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-HpjW9eaFLIg.html
@kimkorngmao
@kimkorngmao 2 года назад
Thanks for that 😘
@ankurdohare2261
@ankurdohare2261 Год назад
what if first page is "/" instead of "/index.html" ? we cannot use link.hred.include in that case
@CodinginPublic
@CodinginPublic Год назад
I did this follow up video with that in mind: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-HpjW9eaFLIg.html Hope that helps!
@ankurdohare2261
@ankurdohare2261 Год назад
@@CodinginPublic you are god😍, Thank you. I resolved one of the story at my firm . Thanks a lot🥳🥳🥳
@ankurdohare2261
@ankurdohare2261 Год назад
@@CodinginPublic Thanks for replying that fast 😁
@nazmussakib9346
@nazmussakib9346 9 месяцев назад
Hey brother, I need some help... Please reply to my comment... I applied this JavaScript on my blogger blog... Everything's perfect but when I'm on the home page the active class is added to all of the links instead of adding to only the home page link... Why is this happening?
@CodinginPublic
@CodinginPublic 9 месяцев назад
Fixed in this video :) ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-HpjW9eaFLIg.html
@sydneysolomon5500
@sydneysolomon5500 Год назад
Hi, I am looking for a tutorial, when you click Home button or any other it takes you the information that is the particular button. Do u have such a tutorial?
@CodinginPublic
@CodinginPublic Год назад
Do you mean anchor links?
@sydneysolomon5500
@sydneysolomon5500 Год назад
@@CodinginPublic Yes...example if you click on the HOME button it should take you whatever is the text about NOME. Same for all the other buttons.
@CodinginPublic
@CodinginPublic Год назад
@@sydneysolomon5500 Been a long time since I did this, but I think this is along the lines of what you want? ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-PolXp-MWJcs.html
@subscribetoDerickChess
@subscribetoDerickChess Год назад
can you show me what you used for the html thx
@CodinginPublic
@CodinginPublic Год назад
Sorry! I didn't save the code for this; just whatever’s in the code pen!
@subscribetoDerickChess
@subscribetoDerickChess Год назад
@@CodinginPublic it doesn't work? and are lists
@CodinginPublic
@CodinginPublic Год назад
@@subscribetoDerickChess I show the HTML in the video at @0:59 hope that helps!
@MaksymMinenko
@MaksymMinenko 2 года назад
The codepen has only the JS file...
@CodinginPublic
@CodinginPublic 2 года назад
Well, because every site is so different and the focus was on implementing the JS for any page. Let me know if you get stuck. Happy to help!
@sebastianszydlowski5834
@sebastianszydlowski5834 2 года назад
This function adds active class to all links when websote is visited for the forst time. How can I remove this class?
@CodinginPublic
@CodinginPublic 2 года назад
Hmm. It shouldn’t. Happy to view your code and give you a solution. Feel free to DM on Twitter or share a public link.
@CodinginPublic
@CodinginPublic 2 года назад
Hey! I saw you commented, but RU-vid deleted it before I could see it. 🙄 feel free to try again or DM me on Twitter at @cpenned.
@CodinginPublic
@CodinginPublic 2 года назад
Okay, so it deleted it, but the preview showed me enough! Ha. The problem is your window.location.pathname will include the directory (/wordpress/) and since your homepage includes that pathname and all four links include that section in their pathname, they're all highlighted. My initial thought is that you should just clip out the "/wordpress/" from the pathname, which you can do with the substring method (assuming all your menu items will always be in that directory, wordpress). The substring takes a number as an argument and basically slices off those indexes from your string. So in all, change … const activePage = window.location.pathname; to … const activePage = window.location.pathname.substring(10); --- Let me know if that doesn't make sense or doesn't solve your problem.
@sebastianszydlowski5834
@sebastianszydlowski5834 2 года назад
@@CodinginPublic Thank you for the reply. Did not work. I noticed it for the first time when the site was on localhost. I will let you know if it is working after migration.
@CodinginPublic
@CodinginPublic 2 года назад
@@sebastianszydlowski5834 Ah-sorry you're still having trouble with it. For what it’s worth, I used the solution I mentioned in your live site (just changed the JS file) and it worked properly in my tests, but it all depends on the folder structure. Happy to help more if it would be a help.
@SharoAliDevelpor
@SharoAliDevelpor Год назад
Wow i need it but plz provide the source code
@CodinginPublic
@CodinginPublic Год назад
In description :)
@ggff8782
@ggff8782 Год назад
Not hover before clicking
@CodinginPublic
@CodinginPublic Год назад
not sure I understand? Did I style it wrong? I can’t remember-this has been a while :)
@surbhipaliwal3576
@surbhipaliwal3576 2 года назад
Sir please give all files
@CodinginPublic
@CodinginPublic 2 года назад
Link in the description!
@MuhammadAdnan2.0
@MuhammadAdnan2.0 Год назад
Bro what about these slugs contact%20Us ?
@CodinginPublic
@CodinginPublic Год назад
Did a follow-up video for these types of situations :) ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-HpjW9eaFLIg.html
@MuhammadAdnan2.0
@MuhammadAdnan2.0 Год назад
@@CodinginPublic great thnx
@beautifularabicnasheed2323
@beautifularabicnasheed2323 2 года назад
code plase
@CodinginPublic
@CodinginPublic 2 года назад
In the description 😊
@MrFreak0r
@MrFreak0r 11 месяцев назад
Easier way with just 2 lines of CSS: .current-menu-item a { color: #FFFFFF !important; background: #2889AE !important; } So much useless stuff with all the html and javascript. I don't want to hack into the pentagn, just make the active menu item highlighted....
@CodinginPublic
@CodinginPublic 11 месяцев назад
This is such a long time ago I’m sure I’d do it differently than however I did it in this video. Just be careful about those !important flags. They can get you into trouble :) I’d also consider using the aria-current=“page” attribute instead of a class to make this more accessible.
Далее
Make Nav Link Active For Each Page With JavaScript
13:58
Top 10 CSS One Liners That Will Blow Your Mind
13:34
Просмотров 932 тыс.
ЮТУБ ТОЧНО ВСЕ!
11:23
Просмотров 863 тыс.
Show Active Nav Link with JavaScript
6:50
Просмотров 17 тыс.
Learn Flexbox CSS in 8 minutes
8:16
Просмотров 1,5 млн
How I Coded An Entire Website Using ChatGPT
18:22
Просмотров 1,9 млн
Subtle, yet Beautiful Scroll Animations
5:04
Просмотров 1,6 млн
Responsive navbar tutorial using HTML CSS & JS
49:25
5 JavaScript Concepts You HAVE TO KNOW
9:38
Просмотров 1,4 млн
World’s Largest Jello Pool
1:00
Просмотров 101 млн
Иваново - город невест
0:20
Просмотров 6 млн