We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,401 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

adding current class

how do you manually add it when the link is www.somesite.com which i would want it to be added to index.html ?

function setActive() {
/*current page function*/
 $('#menu a').each(function(index) {
        if(this.href.trim() == window.location)
            $(this).addClass("current");
    });

this works for any pages that are in the navigation menu.

3
Contributors
2
Replies
16 Hours
Discussion Span
5 Months Ago
Last Updated
3
Views
andyhunter
Newbie Poster
19 posts since Dec 2010
Reputation Points: 9
Solved Threads: 0
Skill Endorsements: 0

Why don't you provide a class on the body tag to identify if you are on this page rather than check your current url.

e.g.

<html>
<body class="somesite">
</body>
</html>

and in your javascript you do this

$('#menu a').each(function() {
  if ($('body.somesite').length) {
    $(this).addClass('current');
  }
});
lambing
Junior Poster in Training
76 posts since Feb 2010
Reputation Points: 10
Solved Threads: 15
Skill Endorsements: 0

Why don't you just use the active pseudo class in CSS?

stbuchok
Practically a Posting Shark
876 posts since May 2011
Reputation Points: 138
Solved Threads: 124
Skill Endorsements: 2

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0602 seconds using 2.71MB