jQuery $('#myLink').text("UpdateValue") appending text, not overwriting?
I'm h开发者_开发百科aving difficulty replacing the text of a link with new text.
I have the following line
$('#myLink').text("UpdateValue");
This used to work before until I made a change to fix something that should have never been broken.. and now this is appending text & not replacing it.
Can somebody please confirm that it should replace the existing text, and not append the text to the existing text? Or am I going nuts??!!
Thanks
(Crazy) Dave
See this comment from http://api.jquery.com/text/:
-- QUOTE --
One quirk for anyone else experiencing this:
<label id="myLabel" />
$("#myLabel").text("newText");
Will continue to append the string newText instead of replacing it. You need to specify the label as:
<label id="myLabel"></label>
Then it will correctly replace the text.
-- END QUOTE --
Does this apply to your code?
It was a PEBKAC error.
a careless copy & paste resulted in the following being pasted into a UserControl:
<a id="lnkShowClipboard" class="ClipboardLink" href="#">
note the absence of </a>
For whatever reason the browser tried to complete the unfinished HTML in its own way & whatever way that was, jQuery didn't agree with it.
Thanks guys
Dave
精彩评论