title: Javascript Hide Element by ID Based on Browser
body: <p>I am trying to show a message to all browsers and remove it though javascript if it is supported. Currently the only way it will be hidden is if I click a hide button. It won't <em>run</em> in my if statement. </p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  
  &lt;script type="text/javascript"&gt;
  var browser=navigator.appCodeName + navigator.appName;
  function hideStuff(id) {
    document.getElementById(id).style.display = 'none';
   }
  
  function supportedBrowser() {
  if (browser == "MozillaNetscape")
    {
    document.write("Browser is Mozilla Netscape");
    }
  else if (browser == "MozillaOpera")
    {
    document.write("Browser is Mozilla Opera");
    hideStuff('browserMessage');
    }
  else
    {
  alert("Please upgrade your browser.");
   }
  }
  //--&gt;
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;a href="#" onclick="hideStuff('browserMessage'); return false;"&gt;Hide&lt;/a&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;p id="browserMessage" style="display: inline;"&gt;Please use a supported browser.&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Changed as according to "bluevoodoo1"</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  
  &lt;script type="text/javascript"&gt;
  var browser=navigator.appCodeName + navigator.appName;
  function hideStuff(id) {
          document.getElementById(id).style.display = 'none';
      }
  function supportedBrowser() {
  if (browser == "MozillaNetscape")
    {
    document.write("Browser is Mozilla Netscape");
    }
  else if (browser == "MozillaOpera")
    {
    document.write("Browser is Mozilla Opera");
    //hideStuff('browserMessage');
    }
  else
    {
  alert("Please upgrade your browser.");
      }
  }
  function init() {
           supportedBrowser();
         //etc
      }
      window.onload = supportedBrowser;
      //--&gt;
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;a href="#" onclick="hideStuff('browserMessage'); return false;"&gt;Hide&lt;/a&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;p id="browserMessage" style="display: inline;"&gt;Please use a supported browser.&lt;/p&gt;
  &lt;p&gt;This text shoudld not be hidden.&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Does anyone know what I am doing wrong?</p>