views:

194

answers:

6

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?

+1  A: 

I found that the following code, when inserted into the site's footer, worked well enough:

<script type="text/javascript">
$("#nav-ask").remove();
</script>

This may or may not require jquery. The site I'm editing has jquery, but unfortunately I'm no javascripter, so I only have a limited knowledge of what's going on here, and the requirements of this code snippet...

Adam Davis
remove removes it. Not hides it. Use $("#nav-ask").hide();
DA
Without using a JavaScript framework like jQuery, the code would be: document.getElementById('nav-ask').style.display = 'none';
jwhat
+4  A: 
.nav ul li a#nav-ask{
    display:none;
}
Brant
ooh, I didn't realize you could address id element in css!
Adam Davis
I think he wanted to do this on call, as opposed to all the time (could be wrong), but instead of: ".nav ul li a#nav-ask", just do "#nav-ask"
ocdcoder
+4  A: 
<style type="text/css">
  #nav-ask{ display:none; }
</style>
jwhat
you are missing the #
Gaby
Forgot to add 4 spaces to format my answer as code. : )
jwhat
+1  A: 

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.

Fermin
+2  A: 

@Adam Davis, the code you entered is actually a jQuery call. If you already have the library loaded, that works just fine, otherwise you will need to append the CSS

<style type="text/css">
    #nav-ask{ display:none; }
</style>

or if you already have a "hideMe" CSS Class:

<script type="text/javascript">

    if(document.getElementById && document.createTextNode)
    {
        if(document.getElementById('nav-ask'))
        {
            document.getElementById('nav-ask').className='hideMe';
        }
    }

</script>
Rob Allen
+1  A: 

you can use CSS selectors

a[href="/questions/ask"] { display:none; }
pixeltocode