<div> Toggles Not Working

I tried to make some divs on my website be toggled on/off when I press a button but it isn’t working for some reason, and always outputs this in the console:
Screenshot 2020-10-14 094909
This is my JavaScript:

function dropDown(id_parameter) {
  var div = document.getElementById(id_parameter);
  hideAll();
  div.style.display = "block";
}
function hideAll() {
  var x = document.getElementByID("div1");
  x.style.display = "none";
  var x = document.getElementByID("div2");
  x.style.display = "none";
}

and my HTML is just

<div id="div1"> 

and

<a onclick="dropDown('div1');">

with a similar thing for div2.

I’m new to JavaScript and used what little knowledge I have of it to make this so if there are any syntax errors let me know.

I think it’s where you used document.getElementByID rather than document.getElementById - note the lower-case d. Hopefully this should work!
Happy Glitching!

2 Likes

Thanks! :slight_smile:

1 Like