1,105,391 Community Members

adding current class

Member Avatar
Newbie Poster
19 posts since Dec 2010
Reputation Points: -1 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]

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 works for any pages that are in the navigation menu.

Member Avatar
Junior Poster in Training
76 posts since Feb 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 15 [?]
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.


<body class="somesite">

and in your javascript you do this

$('#menu a').each(function() {
  if ($('body.somesite').length) {
Member Avatar
Posting Shark
957 posts since May 2011
Reputation Points: 123 [?]
Q&As Helped to Solve: 142 [?]
Skill Endorsements: 2 [?]

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

This article has been dead for over three months: Start a new discussion instead
Start New Discussion
Tags Related to this Article