最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to change text inside anchor tag - Stack Overflow

programmeradmin1浏览0评论

How to change the text 'save' to 'edit' in this html code using jquery

<a id="personalSave" href="#" class="SaveText"> 
<span class="FloatLeft">&lsaquo;</span>
save
<span class="FloatRight">&rsaquo;</span>
</a>

i tried changing the text(save between the spans ) using

$('#personalSave').innerText = "edit";

but its not working..

How to change the text 'save' to 'edit' in this html code using jquery

<a id="personalSave" href="#" class="SaveText"> 
<span class="FloatLeft">&lsaquo;</span>
save
<span class="FloatRight">&rsaquo;</span>
</a>

i tried changing the text(save between the spans ) using

$('#personalSave').innerText = "edit";

but its not working..

Share Improve this question edited Aug 2, 2013 at 10:28 iJade asked Aug 2, 2013 at 10:22 iJadeiJade 23.8k58 gold badges160 silver badges250 bronze badges 4
  • 1 Change it when what? Click on link or what? Improve your question please... – A. Wolff Commented Aug 2, 2013 at 10:24
  • 1 Mhm... What? Can you please explain better? – Niccolò Campolungo Commented Aug 2, 2013 at 10:24
  • Use $('#personalSave').text('edit') instead... – Niccolò Campolungo Commented Aug 2, 2013 at 10:29
  • @LightStyle dat did the trick – iJade Commented Aug 2, 2013 at 10:32
Add a ment  | 

3 Answers 3

Reset to default 4

This is what worked for me

$('#personalSave').text('edit');

Wrap your text also in a span:

<a id="personalSave" href="#" class="SaveText"> 
    <span class="FloatLeft">&lsaquo;</span>
    <span class='txt'>save</span>
    <span class="FloatRight">&rsaquo;</span>
</a>

Now you can select it:

$('#personalSave .txt').text("edit");

This should work but it's probably not the best way to do it:

$("#personalSave").text($("#personalSave").text().replace("save", "edit"));

Better wrap the text in a span and change that.

发布评论

评论列表(0)

  1. 暂无评论