Reputation: 8400
for this html list,
<ul class="buttons">
<li class="back"><a href="#">ABCDE</a></li>
<li class="back"><a href="#">B</a></li>
<li class="back"><a href="#">CEDFRD</a></li>
<li class="back"><a href="#">D</a></li>
<li>E</li>
<li>F</li>
<li>G</li>
<li>H</li>
</ul>
Want append text to the end of the text in anchor tag only if,
How to do this using jquery?
Upvotes: 1
Views: 5376
Reputation: 67187
Use the receiver function of .text()
to accomplish your task.
Try,
$('li.back a').text(function(_,text){
return text + "yourNewText";
});
As per your new edit(only if the text in anchor text is having lenght more than 5 char) you can use,
$('li.back a').text(function(_,text){
return (text.length > 5) ? text + "yourNewText" : text;
});
Upvotes: 1