vlad_kl,
https://learn.javascript.ru/event-delegation
https://learn.javascript.ru/introduc...ik-handleevent
<!doctype html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
.span.redbackground{
background-color: hsla(0, 100%, 50%, 1);
}
</style>
</head>
<body>
<div>
<span class="span">#1</span>
<span class="span">#2</span>
<span class="span">#3</span>
<span class="span">#4</span>
<span class="span">#5</span>
</div>
<script>
let div = document.querySelector('div');
let changeColor = {
handleEvent(event) {
const target = event.target.closest('.span');
if (!target) return;
target.classList.toggle('redbackground', event.type == 'mouseenter')
}};
div.addEventListener('mouseenter', changeColor, true);
div.addEventListener('mouseleave', changeColor, true);
</script>
</body>
</html>