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 in Web Development by gaurav
• 17,580 points
9 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.

Related Questions In Web Development

0 votes
0 answers

How to add a link in Jquery PrettyPhoto to download the image

I am using Jquery PrettyPhoto to have ...READ MORE

Jun 29 in Web Development by gaurav
• 17,580 points
19 views
0 votes
0 answers

How to set jQuery draggable min/max-left and min/max-right

I made a copy of JSbin for ...READ MORE

Jul 20 in Web Development by gaurav
• 17,580 points
10 views
0 votes
0 answers

How to set jQuery draggable min/max-left and min/max-right

I made a copy of JSbin for ...READ MORE

Jul 21 in Web Development by gaurav
• 17,580 points
19 views
0 votes
0 answers

JavaScript or jQuery "Are you sure?" dialog for <A> link?

I have a link in my HTML: <a ...READ MORE

Jul 26 in Web Development by gaurav
• 17,580 points
11 views
0 votes
1 answer

How to set selected value of jQuery Select2?

To set selected value of jQuery Select2 ...READ MORE

answered Aug 5 in Web Development by rajatha
• 7,040 points
15 views
0 votes
0 answers

set text in jquery

If I want to set the text ...READ MORE

Aug 8 in Web Development by gaurav
• 17,580 points
5 views
0 votes
1 answer

What is jQuery?

Hey, jQuery is a fast and concise JavaScript ...READ MORE

answered Feb 14, 2020 in JQuery by kartik
• 37,500 points
308 views
0 votes
1 answer

Error: Global Variable is not accessable to local function

Hey kartik, A variable declared outside a function has a ...READ MORE

answered Feb 19, 2020 in PHP by Niroj
• 82,740 points
283 views
0 votes
1 answer

Uncaught TypeError: Cannot read property 'msie' of undefined - jQuery tools

Hello, Use the following script tag in your ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,740 points
8,878 views
0 votes
1 answer

Uncaught Error: Bootstrap's JavaScript requires jQuery

Hello @kartik, You have provided wrong order for ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,740 points
15,869 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP