If url hash :target is active add active class to li link

Creating a navigation list where you link to different parts of your web page? Want to set different styling to the active navigation link for the hash tagged url? It’s easy to style the div that is active in CSS3 using the :target element, but in order to style the link, you need to add a class to that element.

Your html will look something like this:

 

If the current hash url is equal to a navigation link, you can add an active class to that navigation li element by using the javascript snippet below.