I'm trying to display and hide a div class using JavaScript, so that when someone hits a button a hidden section displays/hides dependent on the state/style. I've managed to display the hidden section, but I can't then hide it again. Here is the code I am using is a file called locationMenu.js.
const locationLink = document.getElementsByClassName('locationLink')[0];
locationLink.addEventListener('click', () => {
if (display = "none") {document.getElementsByClassName('locationMenuDropdown')
[0].style.display = 'block';}
else {document.getElementsByClassName('locationMenuDropdown')[0].style.display
= 'none';}
});
and here is the (simplified) HTML
<div class="header">
<div class="locationMenuDropdown">
<h3>Choose a Location</h3>
<div class="locationButtons">
<div class="et_pb_button"><i class="fas fa-map-marker-alt"></i> Kettering</div>
<div class="et_pb_button"><i class="fas fa-map-marker-alt"></i> Northampton</div>
<div class="et_pb_button"><i class="fas fa-map-marker-alt"></i> Wellingborough</div>
</div>
</div>
<div id="locationMenu"><h4 class="locationLink"><i class="fas fa-map-marker-alt"></i> Locations</h4>
</div>
<script type="text/javascript" src="locationMenu.js"></script>
` instead of a `
– Quentin Feb 14 '18 at 14:10