1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Persistent menu highlight

Discussion in 'jQuery' started by cliff ludo, Oct 22, 2018.

  1. #1
    Hi guys,

    new member here, so sorry if my question is in the wrong place or in the wrong format.

    I've got a "primary" menu that leads to a "secondary" menu and I am highlighting it so:
    SEMrush
    jQuery(document).ready(function($) {

    $("a").each(function() {
    if ((window.location.pathname.indexOf($(this).attr('href'))) > -1) {
    $(this).addClass('activeMenuItem');
    }
    });

    });
    and css so:

    a.activeMenuItem {
    background-color: white;
    font-weight: bold;
    }

    This works just fine, but when a user selects an item from the "secondary" menu the highlighting is lost from the "primary" menu. Is there a way to maintain the highlighting on the "primary" menu?

    Thanks and hello to all in the community!
     
    cliff ludo, Oct 22, 2018 IP
    SEMrush
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    5,870
    Likes Received:
    1,086
    Best Answers:
    22
    Trophy Points:
    400
    #2
    Can you post the link to the site?
     
    qwikad.com, Oct 22, 2018 IP
  3. cliff ludo

    cliff ludo Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    hi there,
    no can do bud, cos it's localhost! sure hope the guys round here have a sense of humour!
     
    cliff ludo, Oct 22, 2018 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    8,927
    Likes Received:
    1,625
    Best Answers:
    232
    Trophy Points:
    515
    #4
    What the bloody blue blazes are you throwing scripttardery at a menu for?!? ESPECIALLY that steaming dung-heap known as jQuery?

    Why not just generate the 'current' class server-side like a good little doobie? In the vast majority of cases this is NONE of any client-side scripting's business.

    But if you could share the full page we could tell your more. Little snippet like that tells us but two things; and Jack left town.
     
    deathshadow, Oct 24, 2018 IP
  5. smo

    smo Well-Known Member

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #5
    If your pages already using JQuery then go for it . But just to crate a simple menu no need to go for JQuery.
    However JQuery UI has beautiful Menu with all your required sub menu , highlighting etc ... This is easy to develop also as no need to write all the code.
     
    smo, Apr 29, 2019 IP