Answer the question
In order to leave comments, you need to log in
Why doesn't target.closest select element by class?
<div class="news-card-1 commentary-closed">
<div class="news-card-pic"></div>
<div class="news-card-right">
<div class="news-card-description">
<h1>What is Lorem Ipsum?</h1>
<p>Lorem Ipsum is simply dummy text of ...</p>
</div>
<div class="news-card-buttons">
<div class="news-card-hashtag">
<p data-hashtag>#Art</p>
</div>
<div class="card-buttons">
<button type="button" class="heart" value="17"></button>
<button type="button" class="list"></button>
<button type="button" class="commentary commentary-empty"></button>
</div>
</div>
</div>
</div>
document.addEventListener('click', openCommentary);
function openCommentary(event) {
if (event.target.classList.contains('commentary')) {
let picture = event.target.closest('.news-card-pic');
console.log(picture);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question