convert the HTML tags to the HTML formatted display

246 Views Asked by At

i have some HTML content in a database, and using impromptu as a light box to display some html content. where want it to be like

This is a Sample Text

but it displays as

<em><strong><span style="color: #ff6600;">This is a Sample Text</span></strong></em>

is there a way to convert the tagged text to the formatted text?

3

There are 3 best solutions below

0
On

RTM, you can do this by using the html: method

2
On

You should be able to just write

$.prompt("<em><strong><span style='color: #ff6600;'>This is a Sample Text</span></strong></em>");

Reference: http://trentrichardson.com/Impromptu/

It is possible though that the HTML content in the database is converted to HTML characters references. See http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

0
On

Here's a simple function that doesn't depend on jQuery, which will convert it exactly like you are wanting:

function str_to_html(text)
{
    var a = document.createElement('div');
    a.innerHTML = text;
    return a.textContent;
}

// This function will convert '&lt;sometag&gt;' to '<sometag>', causing the markup
// to be interpreted properly by the browser for your purpose.