Reputation: 1535
I have this code some link but I cannot change the text with jquery.
I tried
if($("a").text() == 'some link') {
$("a").text('success');
}
but it doesn't work.
Any ideas?
Upvotes: 0
Views: 103
Reputation: 10701
If you are talking about links, then you should get the "href" attribute using the attr property
$('a').each(function(){
if($(this).attr('href')=="some link"){
$(this).text("success");
}
});
I hope this helps.
Upvotes: 0
Reputation: 32591
Do this
$('a').each(function(){
if($(this).text()=="some link"){
$(this).text("success");
}
});
This will look through all a tags one by one and check if they have the "some link". With your code you are looking through all a tags and the text might be "link1link2link3link4"
Upvotes: 4