when i click on the button i want to console.log a message to check if it works but it doesnt do anything when clicked. I have added an if statement to check the element exist before attaching the event but nothing happens.
const watchBtn = document.querySelector('.buttons__nav__watch');
if (watchBtn) {
watchBtn.addEventListener('click', e => {
const watch = e.target.matches('.buttons__nav__watch');
console.log('works');
});
}
<div class="buttons">
<div class="buttons__link">
<button class="buttons__link-btn">IMDB 8.0</button>
</div>
<div class="buttons__nav">
<button class="buttons__nav__like">
click to like
<svg class="buttons__nav__icon">
<use xlink:href="img/sprite.svg#icon-heart"></use>
</svg>
</button>
<button class="buttons__nav__watch">
<svg class="buttons__nav__icon">
<use xlink:href="img/sprite.svg#icon-plus"></use>
</svg>
add to watch list
</button>
</div>
</div>