Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript current tab not updating

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #188478
    Doodayer
    Participant

    i’m using jquery to update the look of my current tab, but it only works if i manually reload the page after i’ve visited it.

    http://codepen.io/Doodayer/pen/dPywxE

    is it my jquery thats at fault?

    #188480
    Paulie_D
    Member

    if you are referring to the appropriate page / link being highlighted then that won’t work as you expect in Codepen as it’s just loading the same code (and thus link) over and over again.

    You need to test in a live online environment with a couple of pages for it to work.

    #188500
    Doodayer
    Participant

    well yes i just used the codepen to show you the code. It won’t work on my local wamp server either.

    #188501
    Paulie_D
    Member

    Without a live link it’s going to be hard to help further.

    However, this is the one I use

    
    $(function(){
        var pathname = (window.location.pathname.match(/[^\/]+$/)[0]);
    
        $('nav ul li a').each(function() {
        if ($(this).attr('href') == pathname)
        {
            $(this).addClass('current');
        }
        });
    });
    
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.