Skip to content Skip to sidebar Skip to footer

Set Anchor As Active With Jquery

i have short question.. i got 3 content boxes and all have a menu with anchor-links to the content-boxes below! when i visit the site the first anchor is set ti active.. when i cl

Solution 1:

Just do the same sort of thing when a link is clicked:

$('.head-nav-button').click(function()
{
    $('a').removeClass('active');
    $('.nav_' + $(this).attr('href').replace('#', '')).addClass('active');
});

http://jsfiddle.net/wv9EQ/7/


Solution 2:

for your code use the simple way

http://jsfiddle.net/wv9EQ/4/

  <li><a href="#2-SP" class="head-nav-button nav_2-SP active">2. SP.</a></li>

Solution 3:

Remove this

for(i in sections){
        if(sections[i] > pos && sections[i] < pos + _height){
            $('a').removeClass('active');
            $('.nav_' + i).addClass('active');
        }  
    }

And just add the "active" class where you need it like here http://jsfiddle.net/wv9EQ/6/


Post a Comment for "Set Anchor As Active With Jquery"