-2

I am trying to hide a button from a dynamic page using the below script

  <a class="hideonClick" id="venueButton" type="button">Find venue providers</a>
<script>
document.getElementById("venueButton").onclick = function() {hideButton()};

function hideButton(){
    //get the button

                venueButton.href="http://evopia.net/?providers-category=venues&catid=123&pagenum=1&viewtype=grid-4&numberofpages=&setorderby=&setorder=";
                venueButton.style.display="none";       
    }
    window.onload = init;
</script>
</pre>

The problem is, I am using a 'href' to redirect to the given link and I want to hide this button only on the used 'href' link. Please help which method can be used.

2 Answers2

0

Your question is a little confusing:

I am using a 'href' to redirect to the given link and I want to hide this button only on the used 'href' link

So it sounds to me you want to simply hide the link when click. This is the approach I would use for that:

document.getElementById("venueButton").addEventListener('click', hideButton);

function hideButton(e) {
  //this.href = "put your url here";
  console.log('commented out setting href for example');
  this.style.display = "none";
}
<a class="hideonClick" id="venueButton" type="button">Find venue providers</a>

If you are simply trying to load data into your view then you should make an AJAX request using XMLHttpRequest to fetch your data, instead of statically reloading the page by pointing href to its own url.

Tom O.
  • 5,133
  • 2
  • 19
  • 33
  • No need for ajax, he has ton of parameters, he can add one more like hideBtn=1, and he will have that parameter on next url and he can check if hideBtn is set, if true hide btn else show btn, no need to complicate :) – Armin Jul 27 '18 at 14:14
  • @Armin in my opinion, adding the parameters to an AJAX request and asynchronously loading data is less complicated than your approach. – Tom O. Jul 27 '18 at 14:18
  • Well you need to write whole function to pass one parameter, i just put it in URL, same thing, less job – Armin Jul 27 '18 at 14:20
  • @Armin you should add your approach as an answer with supporting code example – Tom O. Jul 27 '18 at 14:42
  • @tommyO You are right about AJAX approach but will it hide the button once the page is redirected to the designated link? because the link is using the same view. Thanks. – Umair Rasool Jul 28 '18 at 13:41
  • @Armin is there a parameter which i could use like an if statement to hide the button if user is on that link? i.e `if(view=="link"){ this.style.display=none;}` – Umair Rasool Jul 28 '18 at 13:47
  • You are doing this with PHP not JS, so if(!isset($_GET['hideButton']){#html code to present button;} – Armin Jul 30 '18 at 07:58
-1

Personally, I would add a cookie on click, an hide on button if cookie.

How do I set/unset a cookie with jQuery?