N
N
Ninjito2018-02-03 13:10:28
JavaScript
Ninjito, 2018-02-03 13:10:28

AddEventListener for Nodelist, how to hang a handler on each of the array elements?

It would be necessary that when you click on an element with the block class, the active class is removed or added, I don’t understand what needs to be passed to the function? Or is it not at all?

var blocks = document.querySelectorAll('.block');

    [].forEach.call(blocks, function(/*Что здесь должно быть?*/) {
      item.addEventListener('click', function() {
        if (item.classList.contains('active')) {
        item.classList.remove('active');
      } else {
        item.classList.add('active');
      }
      });
    });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Khokhlov, 2018-02-03
@Ninjito

item

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question