Solved

Help with active link sprite nav

Posted on 2013-02-01
6
237 Views
Last Modified: 2013-03-04
I've got to be doing something wrong.  I have a nav sprite that has a a, a:hover, and a.selected state.  What am I doing incorrect?

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

Open in new window


my html

<ul id="navlist">
							 <li id="home"><a  class="nav" href="/home/" ${page == '/home/' ? 'class="active"' : ''}"></a></li>
							  <li  id="about" class="nav"><a  href="/about-us/" ${page == '/about-us/' ? 'class="active"' : ''}"></a></li>

Open in new window


and my css:

#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.nav:active, a:focus { background: url(images/nav-sprite.png) no-repeat -16px -132px; width: 78px; height: 66px; }
#home a.active { 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.active { background: url(images/nav-sprite.png) no-repeat -101px -132px; width: 94px; height: 66px; }

Open in new window

                                   
Please let me know what i'm doing wrong
0
Comment
Question by:nickinthooz
  • 3
  • 2
6 Comments
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 38845099
jQuery uses the same selectors as CSS so you need to include the # for IDs and the . for classes. Your code needs to select the A like so:

$('#navlist a')
0
 
LVL 16

Expert Comment

by:HagayMandel
ID: 38845300
a
0
 
LVL 6

Author Comment

by:nickinthooz
ID: 38845346
no go chris.  I added the selector and it still isn't working.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 43

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 250 total points
ID: 38845416
Here's a working demo. Have a play and let me know if you get stuck:

http://jsfiddle.net/ChrisStanyon/4r5vg/
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 38845437
Just had another look at your code. Your jQuery is adding a class called 'selected' but your CSS styles a class called 'active'. Maybe that's the problem ;)
0
 
LVL 16

Accepted Solution

by:
HagayMandel earned 250 total points
ID: 38845451
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

816 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now