jQuery(".b2b-btn").click(function() {
jQuery(".b2b-image").removeClass('hideb2bimage');
jQuery(".b2b-text").removeClass('expanded');
jQuery(this).closest('col-b2b').find(".b2b-image").toggleClass('hideb2bimage');
jQuery(this).closest('col-b2b').find(".b2b-text").toggleClass('expanded');
});
.hideb2bimage {
height: 0px;
visibility: hidden;
}
.b2b-text {
height: 0px;
visibility: hidden;
opacity: 0;
transition: visibility 0s ease-out 500ms, opacity 500ms;
}
.expanded {
height: auto;
visibility: visible;
opacity: 1;
transition: visibility 0s ease-in 0s, opacity 500ms;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="main-row">
<div class="col-b2b">
<img class="b2b-image" scr="https://picsum.photos/200/300?random=1">
<p class="b2b-text">this is some text</p>
<button class="b2b-btn">Please Click</button>
</div>
<div class="col-b2b">
<img class="b2b-image" scr="https://picsum.photos/200/300?random=2">
<p class="b2b-text">this is some text</p>
<button class="b2b-btn">Please Click</button>
</div>
<div class="col-b2b">
<img class="b2b-image" scr="https://picsum.photos/200/300?random=3">
<p class="b2b-text">this is some text</p>
<button class="b2b-btn">Please Click</button>
</div>
</div>
I want to show text and hide image upon clicking on the button. But I only want to show the text of the column which button is clicked. Also in case someone click on the first column and it shows the text of one column and then click on the second column button it should hide the text of first column. Above is the code I am using please let me know what mistake I am making. Also I want to make click function on image as well.