title: JavaScript TypeError: Cannot read property 'style' of null
body: <p>I have JavaScript code and below line has problem.</p>
  
  <pre><code>if ((hr==20)) document.write("Good Night"); document.getElementById('Night).style.display=''
  </code></pre>
  
  <p><strong>ERROR</strong></p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'style' of null at Column 69
  </code></pre>
  
  <p>My div tag details are:</p>
  
  <pre><code>    &lt;div id="Night" style="display: none;"&gt;
      &lt;img src="Img/night.png" style="position: fixed; top: 0px; left: 5%; height: auto; width: 100%; z-index: -2147483640;"&gt;
      &lt;img src="Img/moon.gif" style="position: fixed; top: 0px; left: 5%; height: 100%; width: auto; z-index: -2147483639;"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Complete JavaScript:</p>
  
  <pre><code>    &lt;script language="JavaScript"&gt;
      &lt;!--
      document.write("&lt;dl&gt;&lt;dd&gt;")
      day = new Date()
      hr = day.getHours()
      if ((hr==1)||(hr==2)||(hr==3)||(hr==4) || (hr==5)) document.write("Should not you be sleeping?")
      if ((hr==6) || (hr==7) || (hr==8) || (hr==9) || (hr==10) || (hr==11)) document.write("Good Morning!")
      if ((hr==12)) document.write("Let's have lunch?")
      if ((hr==13) || (hr==14) || (hr==15) || (hr==16) || (hr==17)) document.write("Good afternoon!")
      if ((hr==18) || (hr==19)) document.write("Good late afternoon!")
      if ((hr==20)) document.write("Good Night"); document.getElementById('Night').style.display=''
      if ((hr==21)) document.write("Good Night"); document.getElementById('Night').style.display='none'
      if ((hr==22)) document.write("Good Night")
      if (hr==23) document.write("Oh My! It's almost midnight!")
      if (hr==0) document.write("Midnight!&lt;br&gt;It is already tomorrow!") document.write("&lt;/dl&gt;")
      //---&gt;
      &lt;/script&gt;
  </code></pre>
  
  <p>Can someone help me?</p>