Jump to content

ktlr

Member
  • Posts

    5
  • Joined

  • Last visited

Posts posted by ktlr

  1. On 12/5/2022 at 9:45 AM, Diggles said:

    A programmer friend helped me by adjusting the above code to get it to work on my site. I'm assuming these adjustments are needed to get it working in SS 7.1.

    The code below will add an underline to the active tagcloud anchor tag
     

    <!--- Add style="text-decoration: underline;" for currently selected tag filter -------------------------->
    <script>
    (function() {
      const tagCloud = document.querySelector(".sqs-tagcloud");
      if (tagCloud) {
        const currentPath = window.location.pathname + window.location.search;
        const selectTag = tagCloud.querySelector(`li a[href*='${currentPath}']`);
        if (selectTag) {
          selectTag.style.textDecoration = "underline";
        }
      }
    })()
    </script>

    Instead of adding a style, I want to add a class. With my limited JS knowledge I was able to accomplish it by modifying the above script like this

    <!--- Add class="tag-active" for currently selected tag filter -------------------------->
    <script>
    (function() {
      const tagCloud = document.querySelector(".sqs-tagcloud");
      if (tagCloud) {
        const currentPath = window.location.pathname + window.location.search;
        const selectTag = tagCloud.querySelector(`li a[href*='${currentPath}']`);
        if (selectTag) {
    	  selectTag.classList.add("tag-active");
        }
      }
    })()
    </script>


     

    Is this still the code you used for your site? It looks great! I'm trying to do something similar but the code isn't working. 

×
×
  • 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.