如何在 Squarespace 中使用 css 或 jQuery 使超链接在点击后改变颜色?

问题描述 投票:0回答:1

附上我在下面使用的代码

它正在工作,但是一旦我单击手风琴块,该链接打开,链接的颜色就会恢复为默认值。如何编写链接与该链接打开的块之间的关系? Here is the screenshot of the link as soon as I click on isHere is the screenshot of the link after i click on the accordion block, the colore of the link goes back to default

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;
}```
jquery css hyperlink squarespace
1个回答
0
投票

您可以创建一个新类,然后在单击时将所述类附加到适当的元素,并在需要时将其删除。

$('.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>

© www.soinside.com 2019 - 2024. All rights reserved.