E
E
Enter_a_nickname2022-04-18 15:20:47
css
Enter_a_nickname, 2022-04-18 15:20:47

How to change the icon in the menu when going to the page?

Good afternoon! I have a vertical menu with icons located to the left of a page link. I need to change the icon to another if the user has moved to this page. How can I do that?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander3928, 2022-04-18
@Alexander3928

If in JS, then it will refer to the img element and change its src when clicked

W
wadowad, 2022-04-18
@wadowad

I will give an abstract answer to an abstract question in jquery. Maybe someone will need to highlight the class of the active item of the first level in the menu with "human-understandable" URLs:

let url = location.href;

  if (url.slice(-1) == '/') url = url.slice(0, -1);
  $($('#menu').children().get().reverse()).each(function() {
    let link = $(this).children('a').first().attr('href');
    if (link.slice(-1) == '/') link = link.slice(0, -1);

    if (link && url.indexOf(link) === 0) {
      $(this).addClass('current');

      self.current = true;
    }
  });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question