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.

Recommended Answers

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) { …
Jump to Post

All 2 Replies

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');
  }
});
Member Avatar

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.