0

Im trying to use the code to create a sub nav menu and I thought I got a solution but I keep getting the error. Please someone inform me what I am missing thank you!

(P.S I know my code is prob not the best but please cut my a little slack I am just a 16 year old trying to make some money)

HTML

    <div id="navSidepanel" class="sidepanel">
      <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
      <a href="#"><button class="openbtn" onclick="openNav(1)">Socials</button></a>
      <a href="#">Services</a>
      <a href="#">Clients</a>
      <a href="#">Contact</a>
    </div>
    
    <button class="openbtn" onclick="openNav(0)">&#9776;</button>

Javascript

function openNav(x) {   
  if(x = 0){
    console.log("Opened first Nav")
    document.getElementById("navSidepanel").style.width = "100%";
    }
    
    else {
      document.getElementById("navSidepanel2").style.width = "100%";
    }
  }


  /* Set the width of the sidebar to 0 (hide it) */
function closeNav() {
  document.getElementById("navSidepanel").style.width = "0";
} 

2 Answers2

0

You have no element with id navSidePanel2 so the function returns null. Add that id to an element and it will work. Make sure that either the defer attribute is on the script or if it is at the end of the body.

expressjs123
  • 1,580
  • 1
  • 3
  • 17
0

ID #navsidePanel2 is not found anywhere in the code. Please revise the code.

hussain
  • 110
  • 10
  • That's what I forgot, I didn't include it in the code yet because I was tryna test if it worked but it was the very thing that was making it not – Darien Hardy Nov 25 '20 at 06:48