Home > Mobile >  How to Show/Hide element on specifict url/endpoint
How to Show/Hide element on specifict url/endpoint

Time:08-11

Can we make a script that allows to hide certain elements when endpoints are loaded in our website URL???

For example, when someone clicks on a currency option, it creates an endpoint "/?wmc-currency=USD". Or if implemented into the web like this https://www.yoursite.com/product/?wmc-currency=USD.

I want a div or any element to be hidden when "/?wmc-currency=USD" is added to the url.

Any help would be very valuable to me. Thanks very much

CodePudding user response:

function checkEndpoint() {
  if(window.location.search=="?wmc-currency=USD") {
    document.getElementById('testid').style.width = 0;
  }
}
checkEndpoint();

// you can also delete the div if you want but with this, you can always bring 
// it back without having to remake it

make sure you change the id for the div you want

CodePudding user response:

This is the code I ended up using, because style.width doesn't hide the text.... So I use display none

  function checkEndpoint() {
  if(window.location.search=="?wmc-currency=USD") {
    document.getElementById('testid')style.display = 'none';
  }
}
checkEndpoint();.

But still, I thank you very much

  • Related