WordPress.org

Support

Support » How-To and Troubleshooting » current-menu-item & AJAX

current-menu-item & AJAX

  • hundstage
    Member

    @hundstage

    hi,

    i need to highlight my active menu item, i know that the latest method to do so is the current-menu-item class.

    but as i am loading my content via ajax for some reasons, the menu is always on the same page (home).

    does anybody knows the trick to highlight the menu link?

    this ist the page: http://beringer.auskas.net/ (work in progress ;))

Viewing 4 replies - 1 through 4 (of 4 total)
  • wpismypuppet
    Participant

    @wordpressismypuppet

    If you are using ajax to load content onto the page, then use jQuery to add/remove the current-menu-item class from the menu item in question. Something like jQuery(‘#menu-item-8’).addClass(‘current-menu-item’). Don’t forget to use .removeClass() to take it off the “old” link…

    hundstage
    Member

    @hundstage

    ok, cool.

    i ended up doing this:

    $(function() {
        $('#nav ul li a').click(function() {
            $('#nav ul li a').each(function() {
                $(this).removeClass('selected');
            });
            $(this).addClass('selected');
        });
    });

    and then just style my .selected class in css

    Clementine Kruczynski
    Member

    @clementine-kruczynski

    I’m new on jquery and ajax and I’ve been trying to solve this in different ways for three hours and I was getting desperate, it was so simple….. thanks so much!!!

    how do I exactly paste the above mentioned code in the header area of the header.php ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘current-menu-item & AJAX’ is closed to new replies.