In this jQuery tutorial, you’ll learn how to add an active class to a menu item based on the page URL using jQuery… so you can highlight that menu item. You’ll learn:
- how use the jQuery addClass() method
- how to get the current page’s URL path in JavaScript
- how to split a URL in an array of parts
- how to use the JavaScript pop() method
- how to target an element based the value of a specified attributed using jQuery
Watch the tutorial below:
Links mentioned in the video:
- Link to the Complete Web Developer Course with discount.
- My web developer resources page with more code snippets.
Here’s the code I used in the video:
If you get value from this code snippet, please consider sharing it with another developer or group who could benefit from it.