JavaScript JavaScript Display/Hide javascript display hide,javascript display hide div,javascript display hide

I'm using this basic code to hide one block of text and display another and it works well but what do I need to do to have a second click close the text again? Right now it stays open until something else is selected so one or another is always open after the first selection. I added some close links that work but would prefer to click on the title (or anything else) to close it again. Other similar questions seem to either use jQuery or they hide the link after it has been selected.

function showhide(id) {
  if (document.getElementById) {
    var divid = document.getElementById(id);
    var divs = document.getElementsByClassName('hide');
    for (var i = 0; i < divs.length; i++) {
      divs[i].style.display = 'none';
    }
    divid.style.display = 'block';
  }
  return false;
}
<a onclick="showhide('toggle1');">
  <h4>-> Title 1</h4>
</a>
<div class="hide" id="toggle1" style="display:none">
  Some text here. <a onclick="showhide('verify');">close</a>
</div>

<a onclick="showhide('toggle2');">
  <h4>-> Title 2</h4>
</a>
<div class="hide" id="toggle2" style="display:none">
  Other text here. <a onclick="showhide('verify');">close</a>
</div>
Answer:1

Need help to convert below JSON string into JSON object.Even string JSON is valid json (verified by https://jsonlint.com/). JSON: { "condition": "AND", "rules": [{ "id": "amount"...

Need help to convert below JSON string into JSON object.Even string JSON is valid json (verified by https://jsonlint.com/). JSON: { "condition": "AND", "rules": [{ "id": "amount"...

  1. json.parse not working
  2. json.parse not working in javascript
  3. json.parse doesn't work

I draw many circles with some loops via d3.js var line = d3.svg.line() var r = 1 var svg = d3.select("body").append("svg:svg") .attr("width", 1000) .attr("height",1000) for ( var x=0; x<...

I draw many circles with some loops via d3.js var line = d3.svg.line() var r = 1 var svg = d3.select("body").append("svg:svg") .attr("width", 1000) .attr("height",1000) for ( var x=0; x<...

  1. lenovo smart display update loop

this is my html code : <div> <label for="accompanying_person" class="col-sm-4 col-form-label">Select number of accompanying person</label> <div class="col-sm-8"&...

this is my html code : <div> <label for="accompanying_person" class="col-sm-4 col-form-label">Select number of accompanying person</label> <div class="col-sm-8"&...

I want user mouse position while the user is holding down the mouse button continuously? I try to do the with following code: $(div).mousedown(function(eventObj){ console.log(eventObj.clientX); ...

I want user mouse position while the user is holding down the mouse button continuously? I try to do the with following code: $(div).mousedown(function(eventObj){ console.log(eventObj.clientX); ...