S
S
Shimpanze2017-08-21 03:40:25
Python
Shimpanze, 2017-08-21 03:40:25

JavaScript: why is the script not working?

Good afternoon!
When hovering over an element of the collection, it is necessary to assign the class “nozoomed” to all its elements, and specifically to the element on which the mouse is hovered the class “zoomed”.
I do it like this:

// Получаю все нужные элементы
[].forEach.call(
  // Привязываю перебор элементов коллекции с событию «mouseover»
  document.querySelectorAll('nav#menu_3 > ul > li').addEventListener('mouseover', function(e) {
    // Для всех элементов задаю класс «nozoomed»
    e.classList.add('nozoomed');
    // Для элемента на который наведена мышь задаю класс «zoomed»
    this.classList.add('zoomed');
  });
);

Does not work. Please tell me what is wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
Umpiro, 2019-04-22
@Umpiro

from selenium.common.exceptions import NoSuchElementException
try:
     elem = driver.find_element_by_id('text')
     return True
except NoSuchElementException:
     print('Zero element for U!')
     return False

0
0xD34F, 2017-08-21
@Shimpanze

  • querySelectorAll returns a collection of elements, it does not have any addEventListener - it must be applied separately to each element
  • e.classList? What the hell, e is an event object, not a DOM tree element
  • classList.add you do, OK - but where is classList.remove? You probably don't want elements to be able to have both classes at the same time.

As far as I understand, you need something like this , right?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question