Don't paste screenshots of code, paste your actual code instead.
The problem is that getElementsByClassName
returns an HTMLCollection, not a single element, so you can't assign a listener to the collection: select a single element first.
The getElementsBy* methods return HTMLCollections, which can be difficult to work with. Consider using querySelectorAll instead, which returns a static NodeList - unlike an HTMLCollection, it can be iterated over directly, it won't change while it's being iterated over, and it's much more flexible.
Try something like this:
document.querySelectorAll('.alex').forEach((alex) => {
alex.addEventListener('mousemove', () => document.querySelector('.pipo').textContent += 'mooove';
});
Note that NodeList.forEach
is something new-ish, supported as of the past few years - to support ancient browsers, use a plain for
loop or a polyfill. (array methods are generally superior to for
loops: no manual iteration, better abstraction, function parameters)