title: document.getElementById() != null is not working on firefox
body: <p>I have the following script inside my Razor view :-</p>
  
  <pre><code>if (document.getElementById("currentdate") != null &amp;&amp; document.getElementById("currenttime") != null) {
          document.getElementById("currentdate").innerHTML = EMBEDformatAMPM();
  </code></pre>
  
  <p>what i am doing is the folloiwng :-</p>
  
  <ul>
  <li>Since the <code>currentdate &amp; currenttime</code> are only displayed if the user is authenticated . so if the element is not displayed the <code>getElementById.innerHTML</code> will raise a reference exception. so that why i decide to check if these elements exists or not before setting their <code>.innerHTML</code>. 
  My checking is working well on IE and chrome, while on firefox the current date and time will not be displayed even if the currentdate and currenttime DOM elements exists </li>
  </ul>
  
  <p>.. can anyone advice please ?</p>
  
  <p><strong>Edit</strong>
  Here is the generated HTML:-</p>
  
  <pre><code>&lt;section id="login" class="navbar-search pull-right"&gt;
    &lt;span class="username customTopNavText " style=" display:block; "&gt;
        [&lt;a href="/tms/Account/LogOff/" style="color:white"&gt; Logout &lt;/a&gt;]
        &lt;i class="icon-user"&gt;&lt;/i&gt; &lt;strong &gt;   &lt;/strong&gt;
    &lt;/span&gt;
    &lt;div  class="customTopNavText" id="currentdate"&gt;&lt;/div&gt;
    &lt;div  class="customTopNavText" id="currenttime" &gt;&lt;/div&gt;   
        &lt;form class="customSearch"method="GET" action="/tms/Home/Search"&gt;
            &lt;input  class="push-up-button searchmargin" placeholder="Search by tag.." name="searchTerm2" data-autocomplete-source= "/tms/Home/AutoComplete" type="text" style="margin-top:8px"/&gt;&lt;input type="submit" value="Search" class="btn" /&gt;
        &lt;/form&gt;
  &lt;/section&gt;
  
  &lt;div class="top-nav nav-collapse"&gt;
      &lt;ul class="nav"&gt;
          &lt;li class="customTitle" style= "color:#f99406"&gt;TMS - Staging  &lt;/li&gt;
          &lt;li&gt;&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/div&gt;&lt;!--/.nav-collapse --&gt;
  
  &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>where both the currentdate &amp; currenttime are there , but their HTML is not being set using the following script:-</p>
  
  <pre><code>    var el = document.getElementById('currentdate');
      if (el != null) {
          //if (document.getElementById("currentdate") != null &amp;&amp; document.getElementById("currenttime") != null) {
          document.getElementById("currentdate").innerHTML = EMBEDformatAMPM();
          var myVar = setInterval(function () { myTimer() }, 30000);
  
          function myTimer() {
              document.getElementById("currentdate").innerHTML = EMBEDformatAMPM();
          }
          function EMBEDformatAMPM() {
              var d = new Date(),
                  minutes = d.getMinutes().toString().length == 1 ? '0' + d.getMinutes() : d.getMinutes(),
                  hours = d.getHours().toString().length == 1 ? '0' + d.getHours() : d.getHours(),
                  ampm = d.getHours() &gt;= 12 ? 'pm' : 'am',
                  months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
                  days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
              return days[d.getDay()] + ' ' + d.getDate() + ' ' + months[d.getMonth()] + ' ' + d.getFullYear();
          }
          document.getElementById("currenttime").innerHTML = EMBEDformatAMPM2();
  
          var myVar2 = setInterval(function () { myTimer2() }, 30000);
          function myTimer2() {
              document.getElementById("currenttime").innerHTML = EMBEDformatAMPM2();
          }
          function EMBEDformatAMPM2() {
              var d = new Date(),
                  minutes = d.getMinutes().toString().length == 1 ? '0' + d.getMinutes() : d.getMinutes(),
                  hours = d.getHours().toString().length == 1 ? '0' + d.getHours() : d.getHours(),
                  ampm = d.getHours() &gt;= 12 ? 'pm' : 'am',
                  months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
                  days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
              return hours + ':' + minutes;
          }
      }
  </code></pre>
  
  <p>Thanks</p>