Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging what is visible based on the url hash
    primarykey
    data
    text
    <p>Right now I have this list:</p> <pre><code>&lt;ul id="list"&gt; &lt;li id="active"&gt;&lt;a href="#home" id="home-link"&gt;&lt;img src="main home page/purhome.png"&gt;&lt;/a&gt;&lt;/li&gt; &lt;li id="active"&gt;&lt;a href="#info" id="info-link"&gt;&lt;img src="main home page/purinfo.png"&gt;&lt;/a&gt;&lt;/li&gt; &lt;li id="active"&gt;&lt;a href="#gyms" id="gyms-link"&gt;&lt;img src="main home page/purgyms.png"&gt;&lt;/a&gt;&lt;/li&gt; &lt;li id="active"&gt;&lt;a href="#contact" id="contact-link"&gt;&lt;img src="main home page/purcontact.png"&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>And this JQuery:</p> <pre><code>$(document).ready(function(){ $("#home-link").click(function(){ $("#main_info2").hide(); $("#main_info").show(); }); $("#info-link").click(function(){ $("#main_info").hide(); $("#main_info2").show(); }); $("#gyms-link").click(function(){ $("#main_info").hide(); $("#main_info2").show(); }); $("#contact-link").click(function(){ $("#main_info").hide(); $("#main_info2").show(); }); }); </code></pre> <p>When I click on the home link, the URL shows indexp.php#home, which is what i want it to show. This happens for all the links. However if i refresh the page after i click on the info link for example, the main_info div is shown, but the browser still says index.php#info. I want to read the hash somehow to show the correct div depending on what the url says.</p> <p>So for example if I click on the info link, the url shows index.php#info. When I refresh it says the same thing but the main_info div shows when the main_info2 div is supposed to be showing. </p> <pre><code>function getHash() { var hash = window.location.hash; return hash.substring(1); // remove # } </code></pre> <p>So I have that code. Would I do something like this?</p> <pre><code>if hash = 'info' // if url says index.php#info show main_info2 hide main_info if hash = nothing // So if url says index.php show main_info hide main_info2 </code></pre> <p>Any ideas?</p> <p>EDIT**</p> <p>I'm trying to do something like this to make it work:</p> <pre><code>var currentValue = window.location.hash.substr(1) $(document).ready(function() { $("home-link").click(function(){ if(currentValue == "home") { $("#main_info2").hide(); $("#main_info").show(); } }); $("info-link").click(function(){ if(currentValue == "info") { $("#main_info").hide(); $("#main_info2").show(); } }); }); </code></pre> <p>Although that is not working, can someone check the code?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload