?
Solved

Menu Active Tab using javascript

Posted on 2013-02-06
7
Medium Priority
?
398 Views
Last Modified: 2013-02-06
I continue to have problems with getting my sprite to display correctly.  The site I'm working on is:

http://pvcc.inthooz.me/

Here's my javascript

$('#navlist li a').click(function() {
    $('#navlist a').removeClass('selected');
    $(this).addClass('selected');
}); 

Open in new window


My html:
 
  <div class="sprite">
					  <ul id="navlist">
							 <li id="home" ><a class="nav"  href="/" ${page == '/home/' ? 'class="active"' : ''}"></a></li>
							  <li  id="about" ><a class="nav" href="/about-us/" ${page == '/about-us/' ? 'class="active"' : ''}"></a></li>
							  <li  id="new"><a class="nav" href="/new/"></a></li>
							  <li  id="ministries"><a class="nav" href="/ministries/"></a></li>
							  <li  id="mission"><a class="nav" href="/missions/"></a></li>
							  <li  id="watch"><a class="nav" href="/watch-listen/"></a></li>
							  <li  id="members"><a class="nav" href="/members/"></a></li>
							  <li  id="contact"><a class="nav" href="/contact-us/"></a></li>
							   
					  </ul>
			    </div>

Open in new window


My Css:
#navlist li, #navlist a{height:66px;display:inline-block;}
 
#home a:link { background: url(images/nav-sprite.png) no-repeat -16px 0; width: 78px; height: 66px; }
#home a:hover { background: url(images/nav-sprite.png) no-repeat -16px -66px; width: 78px; height: 66px; }
#home a:active { background: url(images/nav-sprite.png) no-repeat -16px -132px; width: 78px; height: 66px; }
#home a.selected { background: url(images/nav-sprite.png) no-repeat -16px -132px; width: 78px; height: 66px; }

#about a:link { background: url(images/nav-sprite.png) no-repeat -101px 0; width: 94px; height: 66px; }
#about a:hover { background: url(images/nav-sprite.png)  no-repeat -101px -66px; width: 94px; height: 66px; }
#about a:active { background: url(images/nav-sprite.png) no-repeat -101px -132px; width: 94px; height: 66px; }
#about a.selected { background: url(images/nav-sprite.png) no-repeat -101px -132px; width: 94px; height: 66px; }

#new a:link { background: url(images/nav-sprite.png) no-repeat -201px 0; width: 106px; height: 66px; }
#new a:hover { background: url(images/nav-sprite.png)  no-repeat -201px -66px; width: 106px; height: 66px; }
#new a:active { background: url(images/nav-sprite.png) no-repeat -201px -132px; width: 106px; height: 66px; }
#new a.selected { background: url(images/nav-sprite.png) no-repeat -201px -132px; width: 106px; height: 66px; }

Open in new window



Thanks in advance.
0
Comment
Question by:nickinthooz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 16

Expert Comment

by:Steve Krile
ID: 38859854
What is the behavior you are trying to fix?
0
 
LVL 30

Expert Comment

by:LZ1
ID: 38859856
The jquery you posted here is different from what you have on your page:

Page:
$('#navlist a').click(function() {
$('#navlist a').removeClass('selected');
$(this).addClass('selected');
}); 

Open in new window


$('#navlist li a').click(function() {
    $('#navlist a').removeClass('selected');
    $(this).addClass('selected');
}); 

Open in new window

Here:
0
 
LVL 6

Author Comment

by:nickinthooz
ID: 38859938
that's because I'm playing with it as we speak
0
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

 
LVL 6

Author Comment

by:nickinthooz
ID: 38859942
I'm trying to keep the active tab until a different page is clicked.
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 38860304
The CSS that effects the 'selected' class is commented out, so it has no effect!
0
 
LVL 30

Accepted Solution

by:
LZ1 earned 2000 total points
ID: 38860382
In order to do what your trying to do, your going to have to do one of 2 things:
1. Read the URL into the Javascript so you know what page your on
OR
2. Use server side scripting to determine the page your on

When a user clicks on the menu item, all your doing is adding and removing a class. That won't persist to the next page because the user hasn't clicked on the nav on that page yet.
0
 
LVL 6

Author Closing Comment

by:nickinthooz
ID: 38862156
This is what I was looking for.
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question