Hide HTML element by id

前端 未结 6 1161
执念已碎
执念已碎 2020-12-29 04:38

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:

  
相关标签:
6条回答
  • 2020-12-29 05:17
    <style type="text/css">
      #nav-ask{ display:none; }
    </style>
    
    0 讨论(0)
  • 2020-12-29 05:17

    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.

    0 讨论(0)
  • 2020-12-29 05:20
    .nav ul li a#nav-ask{
        display:none;
    }
    
    0 讨论(0)
  • 2020-12-29 05:25

    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...

    0 讨论(0)
  • 2020-12-29 05:28

    @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>
    
    0 讨论(0)
  • 2020-12-29 05:28

    you can use CSS selectors

    a[href="/questions/ask"] { display:none; }
    
    0 讨论(0)
提交回复
热议问题