WordPress.org

Ready to get started?Download WordPress

Forums

current-menu-item & AJAX (5 posts)

  1. hundstage
    Member
    Posted 2 years ago #

    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 ;))

  2. wpismypuppet
    Member
    Posted 2 years ago #

    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...

  3. hundstage
    Member
    Posted 2 years ago #

    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

  4. Clementine Kruczynski
    Member
    Posted 1 year ago #

    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!!!

  5. vince23
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic