Как сделать чтобы по нажатию на блок его border подкрашивался жёлтым?
подскажите пожалуйста не пойму как правильно сделать есть выпадающий аккордеон, который состоит из 3 блоков с текстом и один из них должен постоянно быть открыт, это реализовал, но не могу понять как подкрасить слева border в жёлтый цвет блок который открыт, то есть по нажатию блок открывается и закрашивается его border слева в жёлтый, а закрывается предыдущий открытый и его border становится белым. Заранее спасибо.
$(document).ready(function () {
$('.what__subtitle').click(function () {
if ($(this).closest('.what-text__border').find('p').is(':visible')) {
$(this).find('p').slideUp('slow');
$(this).closest('.what-description').children('.what-text__border').toggleClass('what-border');
} else {
$('.what__description').slideUp('slow');
$(this).closest('.what-text__border').find('p').slideToggle('slow');
$(this).closest('.what-description').children('.what-text__border').toggleClass('what-border');
}
});
});
.what-text {
text-align: left;
padding: 0 40px;
}
div.what-text__change {
border-left: 4px solid rgb(255, 218, 26);
}
.what__subtitle {
font-family: "Fira Sans";
font-style: normal;
font-weight: 500;
font-size: 24px;
line-height: 120%;
letter-spacing: -0.03em;
color: #000;
cursor: pointer;
}
.what__description {
font-family: "Fira Sans";
font-style: normal;
font-weight: normal;
font-size: 18px;
line-height: 145%;
color: #A0A0A0;
margin: 0px;
padding-top: 16px;
}
.what__none {
display: none;
}
.what-text__border {
border-left: 4px solid #EAEAEA;
padding: 10px 32px;
margin: 30px 0;
}
.what-border {
border-left: 4px solid #FFDA1A;
}
<div class="col-lg-5 colm-md-5 col-12 what-description">
<div class="what-text">
<div class="what-text__border what-text__change">
<div class="what__box">
<span class="what__subtitle">How does service work?</span>
</div>
<div class="what__wrapper">
<p class="what__description">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
</div>
<div class="what-text__border">
<div class="what__box">
<span class="what__subtitle">Getting started</span>
</div>
<div class="what__wrapper">
<p class="what__description what__none">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
</div>
<div class="what-text__border">
<div class="what__box">
<span class="what__subtitle">Results of using</span>
</div>
<div class="what__wrapper">
<p class="what__description what__none">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Ответы (1 шт):
Автор решения: Проста Miha
→ Ссылка
$(document).ready(function() {
$('.what__subtitle').click(function() {
$(".what-text__border").removeClass("what-text__change");
$(this).parent().parent().addClass('what-text__change');
if ($(this).closest('.what-text__border').find('p').is(':visible')) {
$(this).find('p').slideUp('slow');
$(this).closest('.what-description').children('.what-text__border').toggleClass('what-border');
} else {
$('.what__description').slideUp('slow');
$(this).closest('.what-text__border').find('p').slideToggle('slow');
$(this).closest('.what-description').children('.what-text__border').toggleClass('what-border');
}
});
});
.what-text {
text-align: left;
padding: 0 40px;
}
div.what-text__change {
border-left: 4px solid rgb(255, 218, 26);
}
.what__subtitle {
font-family: "Fira Sans";
font-style: normal;
font-weight: 500;
font-size: 24px;
line-height: 120%;
letter-spacing: -0.03em;
color: #000;
cursor: pointer;
}
.what__description {
font-family: "Fira Sans";
font-style: normal;
font-weight: normal;
font-size: 18px;
line-height: 145%;
color: #A0A0A0;
margin: 0px;
padding-top: 16px;
}
.what__none {
display: none;
}
.what-text__border {
border-left: 4px solid #EAEAEA;
padding: 10px 32px;
margin: 30px 0;
}
.what-border {
border-left: 4px solid #FFDA1A;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-lg-5 colm-md-5 col-12 what-description">
<div class="what-text">
<div class="what-text__border what-text__change">
<div class="what__box">
<span class="what__subtitle">How does service work?</span>
</div>
<div class="what__wrapper">
<p class="what__description">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
</div>
<div class="what-text__border">
<div class="what__box">
<span class="what__subtitle">Getting started</span>
</div>
<div class="what__wrapper">
<p class="what__description what__none">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
</div>
<div class="what-text__border">
<div class="what__box">
<span class="what__subtitle">Results of using</span>
</div>
<div class="what__wrapper">
<p class="what__description what__none">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
</div>