Jump to content

Changing color of Nav element when its active

Recommended Posts

  • Replies 2
  • Views 322
  • Created
  • Last Reply
On 4/11/2021 at 4:22 PM, stringbryce said:

Site URL: http://aldenteenoteca.com

Hey can someone provide me with code to change the color of the nav item when its on that page, tried looking everywhere else not working

 

Add this into Advance-Code injection, change color red to whatever you like

<style>
.header a.active-page {
  color: red !important;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function() {	
	var currentPage = location.hash ? location.pathname + location.hash : location.hash;
	var _a = document.querySelectorAll('.header a[href*="'+currentPage+'"]');

	for (var i = 0; i < _a.length; ++i) {
	  _a[i].className += _a[i].className + " " + "active-page";
	}  
});

</script>

image.thumb.png.2fc7641fa9ed66e16950237861efaff3.png

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

Link to comment
  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.