1

I am trying to hide a div class="axiosnext-arrow" when the current url is www.mysite.com/#home using the following code:

<script language="text/javascript">
    jQuery(document).ready(function($) { 
        $(function(){
            if (window.location.search == "#home") {
                $('.axiosnext-arrow').hide();
            } else {
                $('#navleft').show();
            }
        });
    });
</script>     
Will P.
  • 8,437
  • 3
  • 36
  • 45
user38208
  • 1,078
  • 1
  • 15
  • 31

3 Answers3

2

Please try this:

jQuery(document).ready(function($) { 
    $(function(){
        if (window.location.hash == "#home") {
            $('.axiosnext-arrow').hide();
        } else {
            $('#navleft').show();
        }
    });
});
Beroza Paul
  • 2,047
  • 1
  • 16
  • 16
0
   $(function(){
        if (window.location.hash == "#home") {
            $('.axiosnext-arrow').hide();
        } else {
            $('#navleft').show();
        }
    });

You dont need jQuery(document).ready(function($) { and $(function(){. They do the same thing. $(function() { is the short hand version, see Here.

BenG
  • 14,826
  • 5
  • 45
  • 60
-1

Instead of using window.location.search you could use window.location.pathname or window.location.href and just search for your substring of #home.

This is where my answer came from: Get current URL in JavaScript?

Community
  • 1
  • 1
fMont
  • 19
  • 1
  • 6
  • It would be helpful if it would be impossible to achieve this using `window.location.search`.. – Rayon Sep 23 '15 at 18:08
  • @RayonDabre i tried using window.location.search but it would not bring in #home, only anything that was a parameter. which is why i suggested to use .href. i actually just tried using .pathname and it would not return the #home. Only when i tried .href did it grab #home. – fMont Sep 23 '15 at 18:22