0

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

byarnoldus
  • 38
  • 3
  • Does this answer your question? [Show / Hide elements based on query string value](https://stackoverflow.com/questions/13852056/show-hide-elements-based-on-query-string-value) – SuperStormer Aug 11 '22 at 00:39
  • https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/get – dale landry Aug 11 '22 at 02:51

2 Answers2

0

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

Gage
  • 89
  • 7
0

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

byarnoldus
  • 38
  • 3