0

I have a problem with some Javascript. The code comes up with the following error.

Cannot read property 'style' of null

function openNav() {
    document.getElementById("mySidenav").style.width = "100vw";
    document.getElementById("main").style.marginRight = "100vh";
}

function closeNav() {
    document.getElementById("mySidenav").style.width = "0";
    document.getElementById("main").style.marginRight= "0";
}

How do I fix this problem.

Rob Quincey
  • 2,834
  • 2
  • 38
  • 54
  • 4
    Can you paste your HTML? Looks like you do not have element with `mySidenav` or `main` id defined in HTML – Kukic Vladimir Jul 11 '17 at 08:37
  • first make sure, you find dom node – binariedMe Jul 11 '17 at 08:40
  • Possible duplicate of [Why does jQuery or a DOM method such as getElementById not find the element?](https://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element) – Andreas Jul 11 '17 at 08:43

0 Answers0