Всем привет, такая проблема: не работает скролл наверх страницы. Если убрать картинку из ссылки то все хорошо. При клике в event.target выводится не ссылка, а img. Как исправить?
HTML
<section id="first">
<nav>
<ul>
<li><a class="smooth-scroll" href="#first">First</a></li>
<li><a class="smooth-scroll" href="#second">Second</a></li>
<li><a class="smooth-scroll" href="#third">Third</a></li>
<li><a class="smooth-scroll" href="#fourth">Fourth</a></li>
</ul>
</nav>
</section>
<section id="second"></section>
<section id="third"></section>
<section id="fourth"></section>
<a class="pageup smooth-scroll" href="#first">
<img src="up.svg"/>
</a>
</main>
CSS
display: block;
position: fixed;
bottom: 40px;
right: 40px;
width: 40px;
height: 40px;
z-index: 10;
}
.pageup img {
width: 100%;
height: 100%;
}
JavaScript
const links = document.querySelectorAll('.smooth-scroll');
for (let i = 0; i < links.length; i++) {
links[i].addEventListener('click', function (event) {
event.preventDefault();
const blockID = event.target.getAttribute("href").substr(1);
document.getElementById(blockID).scrollIntoView({
behavior: 'smooth',
block: 'start'
})
})
}
});
target
->currentTarget