A
A
agent11562016-09-18 19:26:58
Yii
agent1156, 2016-09-18 19:26:58

How to change menu highlight using js?

Here is my menu


    And here is the script
    $('ul a').each(function () {
    if (this.href == location.href) $(this).parent().addClass('active')
    });
    How to make it so that when clicking on a non-main element, the class from the main li is removed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Inter Carpenter, 2016-09-19
@Byrger

$('ul a').click(function(){
  $('ul a').each(function () {
    if($(this).parent().attr('class') == 'active')
      $(this).parent().removeClass('active');
  });
});

Your task is wrong. This is an approximate answer to your question, but you can make it more elegant by knowing more about your page code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question