Jump to content

hide div based on anchor value


Go to solution Solved by fife,

Recommended Posts

I have a page with 2 divs that can be hidden.  Now when I load the page the URL looks as follows

 

www.example.com/wedding.php#pyromusicals 

 

or it could be

 

www.example.com/wedding.php#just-fireworks

 

now im trying to hide a different div depending on the anchor value and if there is no anchor then hide them both.  Here is my code so far

 

 

   
  $(document).ready(function() {
 
    // Get # parameter
    var param = document.URL.split('#')[1];
 
 
if (param == 'pyromusicals') {
    $(".hidden-div2").hide();
    }
 
    else if (param == 'purely-fireworks') {
    $(".hidden-div1").hide();
    }
 
 
   });


The problem is that on page load neither works but if you manually hit refresh then the jquery starts working. The links on the page are just html links

 

 
      <li><a href="/wedding-fireworks.php#pyromusicals" title="View information about pyromusical displays for weddings">Pyromusicals</a></li>
            <li><a href='/wedding-fireworks.php#purely-fireworks' title="View information about wedding fireworks"><span>Purely Fireworks</span></a></li>


 

Any ideas.  I am completely new to java and jquery so I'd have no idea where to begin trouble shooting this.

 

Link to comment
https://forums.phpfreaks.com/topic/279757-hide-div-based-on-anchor-value/
Share on other sites

  • Solution

Ok I have solved it.  So when the second anchor is clicked the page does not refresh it just moves.  Too force a refresh ive put another var in the url

 

 

so

 

www.example.com#pyro

 

became

 

www.example.com?string=1#pyro

 

this made the page refresh

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.