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.
精彩评论