Jump to content

Hide input caption when typing with Javascript

Recommended Posts

I'm trying to hide a default Squarespace form caption type when typing with Javascript yet it doesn't seem to work. This must be an issue you must have run into previously. Would really appreciate your help!

Here's my Js bit embeded in the code

const captionBox = document.querySelector(".caption")
captionBox.addEventListener("click", hideCaption);

function hideCaption () {
    const fields = document.querySelectorAll(".field-element")
    const captionText = document.querySelector(".caption-text")    
    fields.forEach(field => {
        if (field.classList.contains("focus-visible")) {
          captionText.style.visibility = "hidden";
        } else {
          captionText.style.visibility = "visible";
        }
    })
}


 

Link to comment
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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.