Jump to content

Make the class 'list-item' act a clickable link if hover.

Go to solution Solved by Lesum,

Recommended Posts

  • Replies 4
  • Views 164
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

  • Solution
Posted

@Hanara Hi! To make the list items clickable, you can add this code under Website > Pages > Website Tools > Code Injection > Header.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

<script>
  $(document).ready(function () {
    $('.user-items-list-item-container .list-item').each(function () {
        const button = $(this).find('.list-item-content__button');
        const link = button.attr('href');
        
        if (link) {
            $(this).css('cursor', 'pointer').on('click', function () {
                window.location.href = link;
            });
        }
    });
  });
</script>

Note: This code will only work if the buttons inside the list items already have URLs linked to them.

If my comments were useful, please like or mark my solution as answer so others can scroll to it quickly. 

Sam
Web Developer & Digital Designer

 Did you find my contribution helpful? Buy me a coffee?

Posted

@Hanara It's basically the same code; you just need to change one class name. Here's the code for auto list carousel:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

<script>
  $(document).ready(function () {
    $('.user-items-list-carousel__slides .list-item').each(function () {
        const button = $(this).find('.list-item-content__button');
        const link = button.attr('href');
        
        if (link) {
            $(this).css('cursor', 'pointer').on('click', function () {
                window.location.href = link;
            });
        }
    });
  });
</script>

 

If my comments were useful, please like or mark my solution as answer so others can scroll to it quickly. 

Sam
Web Developer & Digital Designer

 Did you find my contribution helpful? Buy me a coffee?

Posted

@Lesum Yes, this works, but it depends on hovering over the button first. What I’m aiming for is that if a user  hover over the carousel card will automatically make it act as a clickable link.

Create an account or sign in to comment

You need to be a member in order to leave a comment


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