I have created a mini tab filter filter. The issue that i'm having is that when ever i'm on the current tab the "more" disappears on all the tabs. I don't want it to display when the page first loads because i want to show the content of the first tab. Also for some reason the class "current" isn't applied when the page first loads. Thanks!
$(document).ready(function() {
$('.tab').click(function() {
var tabID = $(this).data('tabid');
$('.iconsContainer').children().removeClass('current');
$(this).addClass('current');
//hide "more" when you are currently on that tab
$('.iconContainerMore').addClass('hideMoreText');
$('.tripctychContent-container').children().hide();
$('.tripctychContent-container').find("[data-blockid=" + tabID + "]").show();
});
});
.field--name-field-topic-2-content,
.field--name-field-topic-3-content {
display: none;
}
.hideMoreText {
display: none;
}
.tab {
cursor: pointer;
}
.iconsContainer {
display: flex;
justify-content: space-between;
}
.tab p:first-of-type:hover {
background: black;
}
.tab p:first-of-type {
padding: 30px;
background: blue;
color: white;
}
.current p:first-of-type {
background: black !important;
}
.tripctychContent-container p {
background: red;
color: white;
}
p {
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="iconsContainer">
<a class="tab" data-tabid="topic1">
<div>
<p>Topic 1 title</p>
<p class="iconContainerMore">More</p>
</div>
</a>
<a class="tab" data-tabid="topic2">
<div>
<p>Topic 2 title</p>
<p class="iconContainerMore">More</p>
</div>
</a>
<a class="tab" data-tabid="topic3">
<div>
<p>Topic 3 title</p>
<p class="iconContainerMore">More</p>
</div>
</a>
</div>
<div class="tripctychContent-container">
<div class="field--name-field-topic-1-content" data-blockid="topic1">
<p>Topic 1 body</p>
</div>
<div class="field--name-field-topic-2-content" data-blockid="topic2">
<p>Topic 2 body</p>
</div>
<div class="field--name-field-topic-3-content" data-blockid="topic3">
<p>Topic 3 body</p>
</div>
</div>