maya_m Posted February 1 Share Posted February 1 Hello everyone! I'm encountering an issue with customizing the filter (archive block). Specifically, I'm looking to give active links a distinct style, such as underlining or making them bold when selected. For instance, if I choose "documentaries" and it filters content accordingly, I'd like the link to be visibly active. Despite trying various codes, I haven't found a solution. A friend knowledgeable in coding, although not specifically with Squarespace, suggested that using JavaScript might be the way to go. Has anyone else faced a similar challenge? I'd greatly appreciate any advice or suggestions. Thank you! Link to the page: https://www.sandranam.me/work Pass: 7u5PY6B6C Earvin 1 Link to comment
Solution jpeter Posted February 4 Solution Share Posted February 4 (edited) @maya_m STEP 1: Add the following JavaScript code to the Footer using Code Injection. This script adds an "active" class on the link that matches whatever filter is defined in the URL. (function () { // Get all the links inside the specified container const links = document.querySelectorAll("#block-yui_3_17_2_1_1706047640137_2381 a"); // Loop through each link and check if its path matches the path in the URL links.forEach((link) => { // Add the "active" class if the pathname of in the URL matches if (window.location.pathname === link.pathname) { link.classList.add("active"); } }); })(); Be sure to add the JavaScript code above between <script> tags like so: <script> // Add JS here </script> Step 2: You can now style the class like so using the following CSS: /* Style active filter link */ #block-yui_3_17_2_1_1706047640137_2381 .active { color: blue; } Edited February 4 by jpeter Earvin 1 Full stack developer who loves helping people out with anything web related. If you'd like to support me, buy me a coffee! Link to comment
maya_m Posted February 4 Author Share Posted February 4 @jpeter You're the best!! It worked perfectly, thank you so much!! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment