Jump to content

How to change search box placeholder on specific pages?

Go to solution Solved by tuanphan,

Recommended Posts

Site URL: https://dragonfly-pentagon-ym6h.squarespace.com/

Hi I'm trying to change the search functions throughout my website depending on the page I'm on. So the homepage allows you to search for the whole website, and the events page lets you search for events only. 

I'm currently using the code 

<script>
  window.addEventListener('DOMContentLoaded', changeSearchPlaceholder);

  function changeSearchPlaceholder() {
    let newText = "Search Me";
    let searchBars = document.querySelectorAll('.search-input');

    searchBars.forEach(el => el.placeholder = newText)
  }
</script>

in the footer, but that ends up changing every single search box placeholder on the whole website. How do I target a specific one?

Link to comment
  • Solution

Remove code from Footer

Next edit page where you want to change this > Add a Code Block (anywhere on page, except footer) > Add this code

<script>
  window.addEventListener('DOMContentLoaded', changeSearchPlaceholder);

  function changeSearchPlaceholder() {
    let newText = "Search Me";
    let searchBars = document.querySelectorAll('.search-input');

    searchBars.forEach(el => el.placeholder = newText)
  }
</script>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

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.