I have the following code in html
function FilterCard(filter) {
event.preventDefault();
var classList = document.getElementsByClassName("collapse");
if (filter === 'All') {
for (let i = 0; i < classList.length; i++) {
classList[i].className = "collapse show";
var childCards = classList[i].firstElementChild.children;
for (let j = 0; j < childCards.length; j++) {
childCards[j].style.display = "inline-flex";
}
}
} else {
for (let i = 0; i < classList.length; i++) {
if (classList[i].className === "collapse show") {
var childCards = classList[i].firstElementChild.children;
console.log(childCards);
var count = 0;
for (let j = 0; j < childCards.length; j++) {
var card = childCards[j].firstElementChild.firstElementChild;
if (card.innerText !== filter) {
childCards[j].style.display = "none";
count++;
} else {
childCards[j].style.display = "inline-flex";
}
}
if (count == childCards.length) {
classList[i].className = "collapse";
}
}
}
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<style>
.card-body .card {
margin: 5px;
width: 18rem;
}
.card {
display: inline-flex;
margin: 5px;
width: 100%;
}
</style>
<div class="container-fluid text-center">
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Filter Card
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#" onclick="FilterCard('All')">All</a>
<a class="dropdown-item" href="#" onclick="FilterCard('Card1')">Card1</a>
<a class="dropdown-item" href="#" onclick="FilterCard('Card2')">Card2</a>
<a class="dropdown-item" href="#" onclick="FilterCard('Card3')">Card3</a>
</div>
</div>
</div>
<div class="container">
<div id="accordion">
<div class="card">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Collapsible Group Item #1
</button>
</h5>
</div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne">
<div class="card-body">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card1</h5>
<p class="card-text">Card Content Goes Here</p>
<a href="#" class="card-link">Link1</a>
<a href="#" class="card-link">Link2</a>
</div>
</div>
<div class="card">
<div class="card-body">
<h5 class="card-title">Card2</h5>
<p class="card-text">Card Content Goes Here</p>
<a href="#" class="card-link">Link1</a>
<a href="#" class="card-link">Link2</a>
</div>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingTwo">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Collapsible Group Item #2
</button>
</h5>
</div>
<div id="collapseTwo" class="collapse show" aria-labelledby="headingTwo">
<div class="card-body">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card3</h5>
<p class="card-text">Card Content Goes Here</p>
<a href="#" class="card-link">Link1</a>
<a href="#" class="card-link">Link2</a>
</div>
</div>
<div class="card">
<div class="card-body">
<h5 class="card-title">Card1</h5>
<p class="card-text">Card Content Goes Here</p>
<a href="#" class="card-link">Link1</a>
<a href="#" class="card-link">Link2</a>
</div>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingThree">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
Collapsible Group Item #3
</button>
</h5>
</div>
<div id="collapseThree" class="collapse show" aria-labelledby="headingThree">
<div class="card-body">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card1</h5>
<p class="card-text">Card Content Goes Here</p>
<a href="#" class="card-link">Link1</a>
<a href="#" class="card-link">Link2</a>
</div>
</div>
<div class="card">
<div class="card-body">
<h5 class="card-title">Card3</h5>
<p class="card-text">Card Content Goes Here</p>
<a href="#" class="card-link">Link1</a>
<a href="#" class="card-link">Link2</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
</body>
</html>
Now what I want to do is filter the cards based on it’s title i.e Card1 , Card2 and so on.
If the Collapsible Group is collapsed then the filter should not display the filtered content for that group.
For example if I have Collapsible Item #2 collapsed , and I select card3 as my filter , then I should only see Collapsible item 1 and 3 which contains only card3 visible if it has any , Collaspsible item#2 should remain collapsed.
If the expanded item , does not have that filter , than the item should automatically collapse.
How do I achieve this using Jquery or Javascript?
prednisone nz – prednisone 20mg prednisone price in usa
modafinil and alcohol – provigil schedule a modafinil prescription
amoxicillin for sale for humans 500 mg – amoxicillin for dogs without vet prescription where to buy amoxicillin 500 mg
vardenafil free sample – vardenafil vardenafil buy brand name vardenafil
ivermectin 1 cream 45gm – ivermetisn.com can you buy stromectol over the counter
cheap generic cialis india – buy cialis discount rx pharmacy online tadalafil
ivermectin 6 tablet – ivermectin for humans ivermectin 3mg tabs
accutane pill 39 mg – accutane canada 40mg accutane australia buy
lyrica cost australia – lyrica without rx viagra canadian pharmacy
bulk order amoxicillin in usa – amoxpll.com amoxicillin without a doctor’s prescription
how to get viagra pills – ed medications online sildenafil tablets from india 100mg tablets
canadian cialis online – how to get cialis prescription in canada tadalafil online purchase
prednisone brand name – canada prednisone 50 mg 40 mg prednisone daily
generic modafinil – provigil 200 mg a modafinil prescription
zithromax 500mg online – zithromax medicine buy zithromax pills
lasix 250 – buying furosemide online where to buy furosemide
clomiphene online 50mg – buy clomid online without prescription clomiphene online
viagra viagra 200mg – viagra viagra 130mg buy viagra from india
stromectol 3 mg dosage – buy ivermectin tablets ivermectin cost in usa
ed pills at cvs – edstronglp erectile dysfunction drug
507742 485869Where else may anybody get that kind of information in such an ideal means of writing? 209377
prednisone 20mg no prescription – prednisone corticosteroids 5mg prednisone daily
sildalis us – order diflucan without prescription cheap metformin 500mg
purchase plaquenil generic – buy hydroxychloroquine 400mg without prescription brand plaquenil 400mg
42359 460518I real delighted to discover this site on bing, just what I was seeking for : D also bookmarked . 892773
It’s very effortless to find out any topic on net as compared
to textbooks, as I found this post at this web page.
Ahaa, its fastidious conversation about this piece of writing
at this place at this blog, I have read all that, so at this
time me also commenting here.
It’s actually a nice and useful piece of information. I am glad that you just shared this useful information with us.
Please keep us up to date like this. Thanks for sharing.
Greetings! Very useful advice in this particular article! It’s
the little changes that will make the most significant changes.
Thanks a lot for sharing!
According to the Florida Lottery, this is the seventh biggest jackpot
in Powerball history, and the eleventh biggest jackpot in U.S.
history.
Here is my ssite :: Visit website