附上我在下面使用的代码
它正在工作,但是一旦我单击手风琴块,该链接打开,链接的颜色就会恢复为默认值。如何编写链接与该链接打开的块之间的关系?
section[data-section-id="64d10fdacb42bb51bdc96a48"] a:link
{
color: #29201a !important;
text-decoration: none !important;
}
section[data-section-id="64d10fdacb42bb51bdc96a48"] active a {
color: #a48f7d !important;
text-decoration: none !important;
}```
您可以创建一个新类,然后在单击时将所述类附加到适当的元素,并在需要时将其删除。
$('.item').click(function(){
$('div').removeClass('highlight');
$(this).addClass('highlight');
});
.highlight {
color: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<section id="section">
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
</section>