I am looking for a little help in trying to retrieve the ID from an URL using JavaScript. I have a main menu system which looks like this
<section id="menu">
<ul id="main">
<li id="first"><a href="index.html">Home</a></li>
<li><a href="Tables.html">League Tables</a><span class="darrow">▼</span>
<ul class="sub1">
<li><a href="Tables.html?id=DivP">Premier Division</a></li>
<li><a href="Tables.html?id=Div1">Division 1</a></li>
<li><a href="Tables.html?id=Div2A">Division 2A</a></li>
<li><a href="Tables.html?id=Div2B">Division 2B</a></li>
<li><a href="Tables.html?id=Div2C">Division 2C</a></li>
<li><a href="Tables.html?id=Div2D">Division 2D</a></li>
</ul>
</li>
<li><a href="Fixtures.html">Fixtures/Results</a></li>
<li><a href="ClubContacts.html">Club Contacts</a></li>
<li><a href="TalkinBaws.html">Talkin' Baws</a></li>
<li><a href="ContactUs.html">Contact Us</a></li>
</ul>
</section>
In the tables page I already have some JavaScript(code added at the end) running using the document.ready()
which hides all the divisions from 1 - 2D and displays only the premier.
When on the tables page i have added a second menu list which shows and hides the divisions based on the users selection using IDs and the .hide()/.show() from JavaScript
<ul>
<li><a href="#" id='showDivP'>Premier Division</a></li>
<li><a href="#" id='showDiv1'>Division 1</a></li>
<li><a href="#" id='showDiv2A'>Division 2A</a></li>
<li><a href="#" id='showDiv2B'>Division 2B</a></li>
<li><a href="#" id='showDiv2C'>Division 2C</a></li>
<li><a href="#" id='showDiv2D'>Division 2D</a></li>
</ul>
This list is working using the .click()
, however the problem I am having is that I want the page to load the desired division depending on the selection made from the main menu.
For example, if the user is on the home page and tries to go directly to Division 2B through the main menu and I am wondering how I can get the ID from the anchor tag in the URL (a href="Tables.html?id=Div2B"
) in order to display the correct division when the page is loaded.
This is the JavaScript I have already:
$("document").ready(function()
{
$('#DivP').show();
$('#Div1').hide();
$('#Div2A').hide();
$('#Div2B').hide();
$('#Div2C').hide();
$('#Div2D').hide();
$('#showDivP').click(function()
{
$('#DivP').show();
$('#Div1').hide();
$('#Div2A').hide();
$('#Div2B').hide();
$('#Div2C').hide();
$('#Div2D').hide();
});
$('#showDiv1').click(function()
{
$('#DivP').hide();
$('#Div1').show();
$('#Div2A').hide();
$('#Div2B').hide();
$('#Div2C').hide();
$('#Div2D').hide();
});
$('#showDiv2A').click(function()
{
$('#DivP').hide();
$('#Div1').hide();
$('#Div2A').show();
$('#Div2B').hide();
$('#Div2C').hide();
$('#Div2D').hide();
});
$('#showDiv2B').click(function()
{
$('#DivP').hide();
$('#Div1').hide();
$('#Div2A').hide();
$('#Div2B').show();
$('#Div2C').hide();
$('#Div2D').hide();
});
$('#showDiv2C').click(function()
{
$('#DivP').hide();
$('#Div1').hide();
$('#Div2A').hide();
$('#Div2B').hide();
$('#Div2C').show();
$('#Div2D').hide();
});
$('#showDiv2D').click(function()
{
$('#DivP').hide();
$('#Div1').hide();
$('#Div2A').hide();
$('#Div2B').hide();
$('#Div2C').hide();
$('#Div2D').show();
});
});
My apologies if this is seen a duplicate question but I am yet to find a definitive answer that I can understand and work with.
Thanks for any help