Javascript – Hide HTML element by id

csshtmljavascript

Hopefully there's a quick and dirty way to remove the "Ask Question" (or hide it) from a page where I can only add CSS and Javascript:

  <div class="nav" style="float: right;">
      <ul>
          <li style="margin-right: 0px;" >
              <a id="nav-ask" href="/questions/ask">Ask Question</a>
          </li>
      </ul>
  </div>

I can't hide the nav class because other page elements use it.

Can I hide the link element via the nav-ask id?

Best Answer

If you want to do it via javascript rather than CSS you can use:

var link = document.getElementById('nav-ask');
link.style.display = 'none'; //or
link.style.visibility = 'hidden';

depending on what you want to do.