I am using two Bootstrap cards in my application. I conceal one of the cards (which is blue in colour) behind a card (which is white in colour) as illustrated below:
...and use the following code to reveal the concealed blue card behind the white card:
$(document).ready(function(){
$(".card-horizontal").click(function(){
$(".backPanel").slideDown("slow");
});
});
resulting in the desired below illustrated effect:
The issue I am having here is that when I click on a card in order to reveal its blue concealed card, all blue concealed cards belonging to all-white cards get simultaneously revealed as illustrated below:
How do I modify the above code to limit this event to only the clicked cards?
Find below my code for the card:
<div class="card w-75 card-horizontal" id="nftCard">
<div class="img-square-wrapper">
<img class="nftImages" src="http://via.placeholder.com/150" alt="Card image cap">
<div class="card-body cardPadding">
<h5 class="card-title">Card title</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
</div>
</div>
</div>
<div class="card w-75 card-horizontal backPanel">
<div class="img-square-wrapper">
<div class="card-body ">
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
</div>
</div>
</div>
You use
$(".card-horizontal")
to get elements by class name. You could give the cards and the backPanels their ownid
and use something like this for each pair:Another way is to use things like parent, child, etc. to navigate the DOM.
In that case, if you like to use a class name, define a new class “white-card” for the click event. Otherwise clicking a blue card (in your code called a "backPanel") also does something.
If all those "white-card"s have the corresponding "backPanel" after them on the same level, the
nextElementSibling
property can be used.Instead of using jQuery, I prefer pure JavaScript (except for the
slideDown
method that you need):I tested the following code in JsFiddle:
HTML
JavaScript
div
changes the color of the reddiv
.div
changes the color of the orangediv
.