<分区>
<分区>
我知道如何将 CSS 注入(inject)网页并更改某个类,但如果我不想更改所有该类怎么办?
例如,假设我有一个 div:
<div class="content">
<p> My favorite color is yellow </p>
</div>
<div class="content">
<p> My favorite color is green </p>
</div>
我想使用内容脚本来编辑 .content
类的 CSS,但仅限那些包含关键字 "green"
我是否必须使用 Javascript,如果是,我该怎么做?
最佳答案
如果您愿意使用 jQuery,您可以使用 :contains() selector .
示例
$(".content:contains('green')").css("color", "green");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="content">
<p>My favorite color is yellow</p>
</div>
<div class="content">
<p>My favorite color is green</p>
</div>
关于javascript - Chrome 扩展仅在具有特定内容的类上注入(inject) css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42044742/