Hello I'm trying to do a show hide div function that will hide the last open div and will open the new one

<script type="text/Javascript">
function HideContent(d) {document.getElementById(d).style.display = "none";}
function ShowContent(d) {document.getElementById(d).style.display = "";}
function ReverseContentDisplay(d)
{if(document.getElementById(d).style.display == "none") {
document.getElementById(d).style.display = "";
}else { document.getElementById(d).style.display = "none"; }}
</script>
I got this function that works for hiding and showing div but it doesnt hide the last div when a new one is open instead opens a new one
someone suggested me to use this

if (previousD != null) { HideContent(previousD); }
previousD = d;

but I'm not really sure how to use it , can someone help me please.
I'm using javascript:ReverseContentDisplay('number') to show/hide the div i'm not sure if/how i should use HideContent/ShowContent functions too.
help please.

and something like this
<div id="02" class="city-list" style="display: none;">
content here
</div>
maybe it should come with a css code too that i missing
I under the logicstic behind this but i cant seem to figure out how to make this work been trying to make this work for weeks