JQuery set active link

0 votes

i have a horizontal CSS Menu with this JQuery code:

function setActiveLink(target) {
        $(".MenuLink").removeClass("active");
        $('a[href=' + target + ']').addClass("active");
        //$('.tabcontent').addClass('hide');
        $(target).removeClass('hide');
    }

    $(document).ready(function(){
    $('.MenuLink').click(function(e) {
        e.preventDefault();
        var target = $(this).attr('href');
        document.location.hash = target;
        setActiveLink(target);
    });
    });

i want to set an active class on the clicked link (and remove all other active classes)

also, i want to be able to add the active class on the parent item when a sub menu item is clicked.

i tried creating the above function, but it doesnt add the class

Jul 20, 2022 in Web Development by gaurav
• 23,260 points

edited 4 days ago 7 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP