开发者

Dynamically update hyperkink link text with Javascript

I wish to change the text of the hyperlink dynamically, and trigger the change with Javascript.开发者_如何学Go

I have html:

<a id="HyperlinkID" href="#" >Original text</a>

Javascript:

$("a#HyperlinkID").text() = "Text changed";

That does not seem to work.

What is the right way to change the text?


Try:

$("a#HyperlinkID").html("Text changed");


$("a#HyperlinkID").text("Text changed");


$("a#HyperlinkID").text("Text changed");


You can do the following:

$("a#HyperlinkID").text("Text changed");


Like this:

$("#HyperlinkID").text("Text changed");


Try this

$('a#HyperlinkID').text("your replacement text goes here");

this may help,

Thanks.


You can make it slightly simpler and faster, if you're interested:

$("#HyperlinkID").text("Text changed");

When you specify the id of an element, you don't need anything else. That's as efficient as it gets.

Otherwise, this is the same as everyone else has suggested.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜