K
K
Keda372017-05-29 13:07:59
Drupal
Keda37, 2017-05-29 13:07:59

Why doesn't the click function add the required classes?

The site has a similar menu .

It was assumed that when you click on Info, the submenu appears and disappears when you click again.

On some pages (currently on the main one), when clicking on INFO, the code does not work, when viewing the DOM tree, when clicking, a pink highlight occurs and
the consol.log disappears on each click, adds 34 errors \ points, and so on every time.

Changing toggle to addClass does nothing.

The error is floating, sometimes pops up on different pages, today it does not leave the main one. I deleted all scripts / plugins, cleared the cache, it's still the same, while on other pages the script works as it should.

PS: Problem site .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
andead, 2017-05-29
@Keda37

If you use Behaviors in Drupal, then you must use context and once() inside:

$("a.nolink", context).once().click(function () {
  $(this).siblings(".menu").slideToggle();
});

RTFM

A
Alexander Lysenko, 2017-05-29
@AlexanderZe

Excuse my poopy jQuery, but isn't that easier?

$('.menu__link').click(function(){
  $(".menu__item").removeClass('active');
  $(this).parent().addClass('active');
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question