gpt4 book ai didi

javascript - 使用 jquery 在 div 内的 anchor 标记中添加类

转载 作者:行者123 更新时间:2023-12-02 14:13:20 25 4
gpt4 key购买 nike

有谁知道如何在 A 标记中添加类:

<a href="/souscription/digital-vie">Subscribe</a>

这是我的 html:

<div class="module" id="prod-subscription">
<div class="entity entity-bean bean-ap-bl-instruct contextual-links-region block container">
<div class="contextual-links-wrapper contextual-links-processed">
<a class="contextual-links-trigger" href="#">Configure</a>
<ul class="contextual-links">
<li class="bean- first last">
<a href="/block/souscription/edit?destination=node/3719"> bloc</a>
</li>
</ul>
</div>
<div class="row">
<div class="col-md-3">
<h2>simple<span>in 3 </span></h2>
</div>
<div class="col-md-6">
<ol>
<li>
<span>1</span><p>text</p>
</li>
<li>
<span>2</span><p>texte testx</p>
</li>
<li>
<span>3</span><p>and text</p>
</li>
</ol>
</div>
<div class="col-md-3">
<a href="/souscription/digital-vie">Subscribe</a>
</div>
</div>
</div>
</div>

最佳答案

你可以使用

$('a[href="/souscription/digital-vie"]').addClass('classHere');

$('div#prod-subscription a[href="/souscription/digital-vie"]').addClass('classHere');

$('a[href="/souscription/digital-vie"]:contains("Subscribe")').addClass('classHere');

$('a[href="/souscription/digital-vie"]:contains("Subscribe")').addClass('classHere');
.classHere{
background : red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="module" id="prod-subscription">
<div class="entity entity-bean bean-ap-bl-instruct contextual-links-region block container">
<div class="contextual-links-wrapper contextual-links-processed">
<a class="contextual-links-trigger" href="#">Configure</a>
<ul class="contextual-links">
<li class="bean- first last">
<a href="/block/souscription/edit?destination=node/3719"> bloc</a>
</li>
</ul>
</div>
<div class="row">
<div class="col-md-3">
<h2>simple<span>in 3 </span></h2>
</div>
<div class="col-md-6">
<ol>
<li>
<span>1</span><p>text</p>
</li>
<li>
<span>2</span><p>texte testx</p>
</li>
<li>
<span>3</span><p>and text</p>
</li>
</ol>
</div>
<div class="col-md-3">
<a href="/souscription/digital-vie">Subscribe</a>
</div>
</div>
</div>
</div>

关于javascript - 使用 jquery 在 div 内的 anchor 标记中添加类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39274599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com