JQuery更改锚链接的值

时间:2014-08-20 19:03:51

标签: jquery

我有一个来自CMS的值,我无法访问并正在寻找一个jquery解决方法。我想基于值定位锚链接然后替换。我知道如何根据课程或ID进行此操作,但我无法编辑这些内容。

这是我渲染的html:

<a class="searchtitle" href="https://sitname.com">STRONG</a>

是否有可能将价值等于强的$(。searchtitle)定位并用新值替换?

3 个答案:

答案 0 :(得分:2)

另一种选择是使用filter()这里是demo

$('.searchtitle').filter(function(){ 
    return $(this).text() == "STRONG"; 
}).text('hello');

答案 1 :(得分:1)

当然,请使用:

$('.searchtitle:contains("STRONG")').html('new text')

<强> jsFiddle example

答案 2 :(得分:0)

试试这个:

$('.searchtitle').filter(function(){
    return $(this).html()=="STRONG";
}).html("new value");
相关问题