Jump to content

Target last visible element

Recommended Posts

Does anyone know how I can target the last visible tag on a summary item?

$(function () { 
$('.summary-metadata-item--tags > a:visible:last').addClass('mk-last-visible');

I tried using the above script. It works in code-pen but not when I add it to code injection header in Squarespace.

Can anyone tell me why this isn't working and how I can fix it?


I have CSS already set up to target the summary block on the Healthcare Practices tab here:

website: https://beehyve.squarespace.com/adhd-support


Link to comment
  • Replies 1
  • Views 1.2k
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Hi @melaniejaane!

I found in the jQuery documentation that it says that the `:last` selector selects the last matched element. I think that means the last instance that matches the selector, and thus only one item. 

I was going to recommend the `last-child` selector, but just in case the `last-child` is hidden, here is a better solution. This selects the last one for the tag section of each summary item (actually the last tag of each tag section).

$(function () { 
    $('.summary-metadata-item--tags').each(function() {

Hope this helps!

Daniel Rodrigues | Excito LLC
Squarespace Web Design for Photographers & Creatives
🌐 https://www.excitollc.com/ | ✉ Contact Me: daniel@excitollc.com
💡 Squarespace Enthusiast | 📖 Squarespace Design Blog for Photographers
🤝 Always happy to help and collaborate! Connect with me on LinkedIn.

Link to comment

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.