Code

Hide/show Items based on URL Parameter

Show or hide divs or elements based on the parameter within a URL in Webflow. This Javascript code allows you to make your Webflow site even more dynamic by allowing you to customize elements on the page based on the URL parameter provided.

Hide/show Items based on URL Parameter preview

Show or hide divs or elements based on the parameter within a URL in Webflow. This Javascript code allows you to make your Webflow site even more dynamic by allowing you to customize elements on the page based on the URL parameter provided.

How to add it

  1. Add the custom Javascript code to the closing body section of your pages custom code
  2. Update the element IDs based on your element IDs
  3. Update the URL based on the parameters set within your Javascript code

The code

Javascript
                      <script>
const queryString = window.location.search;
console.log(queryString);

const urlParams = new URLSearchParams(queryString);
if (urlParams.has('partner')) {
    var partnerBtn = document.getElementById("partner-btn");
    partnerBtn.style.display = "inline-block";
}
if (urlParams.has('creator')) {
    var creatorBtn = document.getElementById("creator-btn");
    creatorBtn.style.display = "inline-block";
}
</script>

                    

Browse similar code snippets

Language

More from Corey Moen

Profile →

Related Webflow questions

All answers →

Similar code snippets

All code snippets →