I have <label class='ash'>Comment Removed</label>
in the database.
When I show this on the grid. I get this on the page:
<label class='ash'>Removed</label>
Actually I should just get Removed in Gray color
How can I convert this to Html like I do in MVC 3 Razor view?
@Html.Raw(HttpUtility.HtmlDecode(comment.txt)) works fine
I am using jquery 1.6 on MVC 3
I tried:
$("<label class='ash'>Comment Removed</label>").html()
unescape($(txt)).html()
May be it is simple, but can't figure it out
You could use $('. gettext'). text(); in jQuery.
parseHTML uses native methods to convert the string to a set of DOM nodes, which can then be inserted into the document. These methods do render all trailing or leading text (even if that's just whitespace).
jQuery is a lightweight, "write less, do more", JavaScript library. The purpose of jQuery is to make it much easier to use JavaScript on your website. jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code.
jQuery :
var YuorHtml = "<p>Some Text <em>Some Text</em> <strong>Some Text</strong></p>";
$('#YuorID').html(YuorHtml)
This should do the trick for you:
var elemString = $('<div/>').html("<label class='ash'>Comment Removed</label>").text();
Here's a demo showing it being appended to the body ->
If you need to do this multiple times, you could simplify with a function, like so:
function DecodeHtml(str) {
return $('<div/>').html(str).text();
}
var encodedStr = "<label class='ash'>Comment Removed</label>";
$('body').append(DecodeHtml(encodedStr));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With