Reputation: 177
I'm attempting to use jquery to find <
or >
and replace it with <
or >
. The idea is to change this from a text element into a live div tag.
I have this jsfiddle but it doesn't seem to be replacing those characters correctly because I still see "" in the output.
$('#myText').each(function() {
var text = $(this).text();
text = text.replace("<", "/\</g");
text = text.replace(">", "/\>/g");
$(this).text(text).clone().appendTo("#output").css("color", "blue");
preventDefault;
});
Why isn't this turning into a live div?
Upvotes: 0
Views: 458
Reputation: 104
Because you are using .text() function and .text() is equivalent to innerText in standard javascript, try to use .html(), which is equivalent to innerHTML, instead and most probably it will work.
Upvotes: 1
Reputation: 6917
try changing .text()
to use .html()
$(this).html(text).clone().appendTo("#output").css("color", "blue");
Upvotes: 4