byrdr
byrdr

Reputation: 5487

JQuery change value of anchor link

I have a value coming in from a CMS which I don't have access to and am looking for a jquery workaround. I'd like to target an anchor link based on value and then replace. I know how to do this based on class or ID but I don't have access to edit those.

Here is my rendered html:

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

Would it be possible to target $(.searchtitle) where the value equals strong and replace it with a new value?

Upvotes: 1

Views: 52

Answers (3)

Brian Dillingham
Brian Dillingham

Reputation: 9356

Another option is to use filter() Here's a demo

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

Upvotes: 2

Amin Jafari
Amin Jafari

Reputation: 7207

Try this:

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

Upvotes: 0

j08691
j08691

Reputation: 207901

Sure, use:

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

jsFiddle example

Upvotes: 1

Related Questions