how do you make a <li> active and show a div based on the url?

Hi,

I have a ul nav system for a contact page that works but i need to make the general tab in the active state when the url is contact/index.html.

This is what I have so far.

Thanks for the Help!

<script type="text/javascript">
	$(document).ready(function(){
		$(".label_copy").hide(); // Hide all tab content divs by default
		$("a[href='"+location.hash+"']").closest("li").addClass("active");
         $(location.hash).show();	
		$(".contact_nav ul li").click(function(){ //Fire the click event
			$(".contact_nav ul li").removeClass("active");
			$(this).closest("li").addClass("active"); // Remove pre-highlighted link
			var activeTab = $("a",this).attr("href"); // Catch the click link
			$(".label_copy").hide(); // hide currently visible tab content div
			$(activeTab).fadeIn(); // show the target tab content div by matching clicked link.
			
			return false; //prevent page scrolling on tab click
		});
	});
</script>	
<style>
.contact_nav {
text-align:left;
margin-left:-30px;
margin-top:5px;
width:705px;
}
.contact_nav li{
    display: inline-block;
    text-align: left;
    list-style-type:none;
    background-color:#417DBE;
    margin: 0px 6px 5px 0px;
    padding: 10px 15px 5px 5px;
	width:100px;
	height:75px;
	color:#FFF;
    -webkit-border-radius: 8px;
    -moz-border-radius: 8px;
    border-radius: 8px;
}

.contact_nav li:hover{
	background-color:#CCC;
	height:75px;
    padding: 10px 15px 5px 5px;

}
.contact_nav li:hover a {
 color: #000;
 }
.contact_nav li a{
    text-decoration: none;
    color: #FFFFFF;
    font-family:Georgia, "Times New Roman", Times, serif;
    font-size: 20px;
	line-height:1.5em;  
}

.contact_nav li.active {
background-color:#ccc;
color:#000000;
}
.contact_nav li.active a {
color:#000000;

}
.contact_nav ul li {
cursor:pointer
}

.label_copy {
margin-left:25px;
width:650px;
}
</style>


<div id="contact_nav" class="contact_nav" style="width:685px;">
	<ul style="width:685px;">
    	<li id="6"><a href="#general">General Information</a></li>
    	<li id="7"><a href="#member">Member Services</a></li>
    	<li id="8"><a href="#patient">Patient Safety</a></li>
        <li id="10"><a href="#press">Press Inquiries</a></li>
        <li id="1"><a href="#web">Website Feedback</a></li>
    </ul>
   
  <div id="member" class="label_copy">
 <p>Member info.</p>
    </div>
     <div id="web" class="label_copy">
 <p>Web info</p>
    </div>
 <div id="general" class="label_copy">
 <p>General info.</p>
    </div>
<div id="patient" class="label_copy">
 <p>Patient info.</p>
 </div>
 <div id="press" class="label_copy">
 <p>Press info</p>
 </div>
    </div>

Open in new window

smfmetro10Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
<script type="text/javascript">
	$(document).ready(function(){
		$(".label_copy").hide(); // Hide all tab content divs by default
		lhash=location.hash
		if(lhash==""){
			lhash="#general"
		}

		$("a[href='"+lhash+"']").closest("li").addClass("active");
		$(lhash).show();	

		$(".contact_nav ul li").click(function(){ //Fire the click event
			$(".contact_nav ul li").removeClass("active");
			$(this).closest("li").addClass("active"); // Remove pre-highlighted link
			var activeTab = $("a",this).attr("href"); // Catch the click link
			$(".label_copy").hide(); // hide currently visible tab content div
			$(activeTab).fadeIn(); // show the target tab content div by matching clicked link.
			
			return false; //prevent page scrolling on tab click
		});
	});
</script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
duncanb7Commented:
I have a ul nav system for a contact page that works but i need to make the general tab in the active state when the url is contact/index.html.

This is what I have so far.

What is your question, could you write it more in detail and step by  step for viewer ?

Please see attachment, no any console error from developer tools


Duncan
e4.php
0
smfmetro10Author Commented:
Once again Gary you have saved me! I think I owe you one of those cans of Duff!!

Thanks again!
0
GaryCommented:
:o)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.