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
  • Views 369
  • Created
  • Last Reply

Archived

This topic is now archived and is closed to further replies.

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