Is there a way to add a specific class to an element when clicking a button, without using the .click function on every individual div? It needs to be added only to the corresponding element within the same box as the clicked button. I'm not sure if this is possible with jQuery since I am unfamiliar with it.
$(".btn-top-heart").click(function() {
$(".heart-right").addClass('red');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li>
<h4 class="panel-title">
Test 1
<span class="heart-right"><i class="fa fa-heart" aria-hidden="true"></i></span>
</h4>
<button class="btn-top-heart">
<a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="13727272537272723d707c7e">[email protected]</a>">Sell</a>
</button>
</li>
<li>
<h4 class="panel-title">
Test 2
<span class="heart-right"><i class="fa fa-heart" aria-hidden="true"></i></span>
</h4>
<button class="btn-top-heart">
<a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="65040404250404044b060a08">[email protected]</a>">Sell</a>
</button>
</li>
<li>
<h4 class="panel-title">
Test 3
<span class="heart-right"><i class="fa fa-heart" aria-hidden="true"></i></span>
</h4>
<button class="btn-top-heart">
<a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="adccccccedcccccc83cec2c0">[email protected]</a>">Sell</a>
</button>
</li>
<li>
<h4 class="panel-title">
Test 4
<span class="heart-right"><i class="fa fa-heart" aria-hidden="true"></i></span>
</h4>
<button class="btn-top-heart">
<a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="52333333123333337c313d3f">[email protected]</a>">Sell</a>
</button>
</li>
<li>
<h4 class="panel-title">
Test 5
<span class="heart-right"><i class="fa fa-heart" aria-hidden="true"></i></span>
</h4>
<button class="btn-top-heart">
<a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="75141414351414145b161a18">[email protected]</a>">Sell</a>
</button>
</li>
</ul>
Any assistance would be greatly appreciated :)