My webpage features various cards with different keywords:
<div class="item">
<div class="hashtags">
<span><a href="#">Technology</a></span>
<span><a href="#">Innovation</a></span>
</div>
</div>
<div class="item">
<div class="hashtags">
<span><a href="#">Healthcare</a></span>
<span><a href="#">Cybersecurity</a></span>
</div>
</div>
In addition, I have pills that can be toggled on/off:
<div class="hashtags">
<span class="active"><a href="#">Healthcare</a></span>
<span class="inactive"><a href="#">Technology</a></span>
<span class="inactive"><a href="#">Innovation</a></span>
<span class="inactive"><a href="#">Cybersecurity</a></span>
</div>
The goal is to click on a pill for "Healthcare", which then displays only the items containing "Healthcare" in their hashtag class, hiding all other items. I've been looking into how to filter/toggle content based on specific criteria, but haven't found a solution yet. Here's the JavaScript I have so far, which handles toggling the active/inactive classes of the pill styling:
$('.hashtags>span').click(function() {
$(this).toggleClass('inactive');
$(this).toggleClass('active');
});
I'm aware there are ways to search HTML and compare strings using JS or jQuery, but I'm unsure if that's the best approach. Any input or advice would be greatly appreciated. Thank you!