【发布时间】:2011-09-17 09:14:48
【问题描述】:
设计者想将公司名称设为蓝色,但公司名称嵌入在文本中,周围没有任何 html 元素。
我希望能够找到一个字符串并只将该字符串设置为蓝色
我有这段代码,但它使整个文本变成蓝色
$(function() {
$('div:contains("The Company Name")').css("color","blue");
});
这是示例代码
<div>The company name is great and makes a lot of happy customers</div>
<div>You can have more info on <a href="link">The company name</a>[...]</div>
这是我想要的结果
<div><span style="color:blue;">The company name</span> is great and makes a lot of happy customers</div>
<div>You can have more info on <a href="link"><span style="color:blue;">The company name</span></a>[...]</div>
有人吗?
【问题讨论】:
-
它甚至不会将第一个
div设为蓝色,因为它区分大小写。 -
为什么要使用jQuery?