Set span.html("test <!-- html comment -->")
i'm trying to dynamically add HTML comments to a span's HTML. however, every time i do a .html(myText) - the html comments in myText disappear. doing a .text(myText) shows the comments by replacing the < with < so i dont want that. I'm essentially using the comments as placeholders, and when i change the value inside the placeholder -- i still want the comment placeholder indicator to stay!! help!!
ex:
-
function ReplaceText()
{
// Logic to figure out where "test" is and replace it with new text
var newTxt = "This is a <!-- [holder] -->new test<!-- /[holder] -->";
$('#txt').html(newTxt);
// What renders in the generated source is now "This is a new test" with no comments.
}
<span id="txt">This is a <!-- [holder] -->test<!-- /[holder] --></span>