How can I target the correct .card element even if it has children that are clicked?
.card.animate
<-- i want this
if currentTarget is used it will do something like this
wine_content.animate
<-- not what I want
or
.card h4.animate
<--- not what I want.
edit: I am really tempted do just do a for loop and addListener on each card from an array of elements. Is this so wrong?
var card = document.getElementById('wine_content');
card.addEventListener("click", function (e) {
if (e.target !== e.currentTarget) {
e.target.classList.toggle('animate');
}
e.stopPropagation()
}, false);
/********************/
/* WINE CARDS */
/********************/
#wine_content {
background-color: #e5e5e5;
}
.cards {
display: flex;
flex-wrap: wrap;
}
/* NOT WHAT I WANT */
.card h4.animate {
color: #F00;
}
/* EXACTLY WHAT I WANT no matter the node in the child family line.*/
.card.animate h4 {
color: #0F0;
}
.card {
flex-grow: 1;
flex-basis: 30em;
height: 150px;
margin: 0 10px;
}
.card-face {
background-color: #fff;
}
<div class="content">
<section id="wine_content">
<div class="cards">
<div class="card">
<div class="card-face">
<h4>The Prisoner</h4>
<p>Merlot</p>
<p>Diamond Peaks</p>
<p>2012</p>
</div>
</div>
<div class="card">
<div class="card-face">
<h4>The Prisoner</h4>
<p>Merlot</p>
<p>Diamond Peaks</p>
<p>2012</p>
</div>
</div>
<div class="card">
<div class="card-face">
<h4>The Prisoner</h4>
<p>Merlot</p>
<p>Diamond Peaks</p>
<p>2012</p>
</div>
</div>
<div class="card">
<div class="card-face">
<h4>The Prisoner</h4>
<p>Merlot</p>
<p>Diamond Peaks</p>
<p>2012</p>
</div>
</div>
<div class="card">
<div class="card-face">
<h4>The Prisoner</h4>
<p>Merlot</p>
<p>Diamond Peaks</p>
<p>2012</p>
</div>
</div>
<div class="card">
<div class="card-face">
<h4>The Prisoner</h4>
<p>Merlot</p>
<p>Diamond Peaks</p>
<p>2012</p>
</div>
</div>
<div class="card">
<div class="card-face">
<h4>The Prisoner</h4>
<p>Merlot</p>
<p>Diamond Peaks</p>
<p>2012</p>
</div>
</div>
</div>
</section>
</div>