Streaming live at 10am (PST)

Hide elements when url contains a certain parameter

Hey guys,

here’s a page example https://raminkhazev2.webflow.io/collection/16-shandara-cres where I want to hide 2 elements in the footer - “Ramin Khaze The Difference.” and “Schedule showing”, when url contains a certain parameter, for example “?mls”

I’ve found a similar topic here but I must be doing something wrong (I’m a beginner in coding) because nothing’s working for me.

Does anybody know a way to do it in Webflow? I will apreciate any help and a piece of advice! Thanks in advance!


Here is my site Read-Only: https://preview.webflow.com/preview/raminkhazev2?utm_medium=preview_link&utm_source=designer&utm_content=raminkhazev2&preview=e51468d0cea14ae26530152edb7b7eec&pageId=5f01ab324c8ac699c727d144&itemId=5f01ab324c8ac6ec1827d1e6&mode=preview

I think the script in your collections page is using jQuery. If you haven’t already, you’ll need to add jQuery to your page. (Maybe you’ve added it already, but I didn’t see it.) This page has some options:
https://www.w3schools.com/jquery/jquery_get_started.asp

If that doesn’t work, an alternative might be to do this without jQuery. Something like:

    // find the element
    let goBackButton = document.getElementById("goBackButton");

    // add the click event
    goBackButton.addEventListener("click", function() {
				window.history.back();
			});

(For this to work, you’ll need to give your go back button an ID. Click the div block, go into its settings, and add an ID of goBackButton.)

Thank you for the responce! But it doesn’t solve what I’m trying to achieve…

Sorry, I forgot you were trying to hide the elements based on the URL parameters. Here is a more complete answer.

  1. Determine if the URL contains the parameter
    This site has a pretty good explanation of how to get the value of a parameter, or check if it exists.
    https://www.sitepoint.com/get-url-parameters-with-javascript/

You can also refer to this Webflow forum post.

  1. Hide the elements
    If you give the element an ID of “raminkhaze” using the Webflow interface, you could do the following:
var x = document.getElementById("raminkhaze");
x.style.display = "none";

Putting these together, I imagine something like this would work:

const queryString = window.location.search;
console.log(queryString);

const urlParams = new URLSearchParams(queryString);
if (urlParams.has('mls')) {
  var x = document.getElementById("raminkhaze");
  x.style.display = "none";  
}

Thank you so much for helping me and spending your time, it worked perfect!!! :heart_eyes: I’m sending lots of bonuses to your Karma :relaxed:

Great. I’m glad this worked!

And thanks for that, I’ll take all the karma I can get :smiley: