1

I have on my ui following html elements

<button onclick="getLocation()">Try It</button>

<p id="long"></p>Longitude<br>
<p id="lat"></p> Latitude<br>
<input type="text" id="ethaddress" placeholder="Enter your ETH address">
<button onclick="writeData()">Submit</button>

when someone visits the site i only want to show the user the "try me" button. once he clicks the "try me" button i want this button to dissapear and i want to show the elements with the id long, lat and ethaddress and the submit button

You find a link to an example here: http://shiny-reaction.surge.sh

yappy twan
  • 801
  • 1
  • 8
  • 11
  • Does this answer your question? [JavaScript hide/show element](https://stackoverflow.com/questions/6242976/javascript-hide-show-element) – Heretic Monkey Oct 17 '20 at 22:37

2 Answers2

2

EDIT Now your issue is that in your js file your getLocation() function is defined as:

function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else {
  //  x.innerHTML = "Geolocation is not supported by this browser.";
  }
}

So that will not be hiding or showing anything, you need to update this.

In vanilla js, you could try this:

function getLocation(btn){
  btn.style.display = "none";
  document.getElementById("form").style.display = "block";
}
#form{
  display: none;
}
<button id="button" onclick="getLocation(this)">Try It</button>
    
<form id="form">
  <p id="long"></p>Longitude<br>
  <p id="lat"></p> Latitude<br>
  <input type="text" id="ethaddress" placeholder="Enter your ETH address">
  <button onclick="writeData()">Submit</button>
</form>
anon
  • 816
  • 5
  • 17
1

Depending if you want the elements to take up space you could go with visibility: hidden; or display: none;. You set app an eventlistener to change the display property to block. You can do this in pure JS or Jquery with addClass.

Ale Plo
  • 799
  • 4
  • 11