Jump to content

Javascript for Header help

Recommended Posts

site: https://grouper-azalea-byr2.squarespace.com/

password: lara



I am using a javascript code in my footer code injection area that was given to me by a member here on the forum. However, I am having a tiny issue with it but haven't heard back from the OG member, so starting a new thread in hopes of solving this for my client. My request was to: hide the site title of the first page only, first section only (site title appearing after scrolling past the first section). The code that was given to me works GREAT. However, the code does this for every page of the site, when I want it active only on the homepage. Can someone help me make this happen? Code down below: 


const logo = document.getElementById('site-title'); // get reference to sitelogo element
const landingSection = document.querySelector('#page #sections section:first-of-type'); 

const observer = new IntersectionObserver(entries => {
  entries.forEach(entry => {
    if (entry.target === landingSection) {
      if (!entry.isIntersecting && entry.intersectionRatio === 0) {
      } else {


  .hidden {
    visibility: hidden;


Link to comment
  • Replies 7
  • Views 371
  • Created
  • Last Reply

Top Posters In This Topic

  • 2 weeks later...
On 5/3/2023 at 6:49 PM, kaydotjpg said:

The code that was given to me works GREAT. However, the code does this for every page of the site, when I want it active only on the homepage.

The code is missing a section that checks if the page has loaded, which is why it didn’t work when you tried it in the per-page header injection. It will load too early. You could move it to a Code Block instead, placed at the very bottom of the homepage, to give the content time to load.

Alternatively, you could prefix the selectors in the querySelector method to include the .homepage class. This would ensure it only works when the class is included. 

Edited by paul2009

About me: I'm Paul, a SQSP user for over 18 yrs and a Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL, providing high quality original extensions to supercharge your Squarespace website. 
Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links.
Forum advice is completely free. You can thank me by selecting a feedback emoji below. Buying a coffee is optional.

Book paid help with domains: Connect a GoDaddy domain. Connect a Squarespace Domain. Domain assistance

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.