Search code examples
javascriptjquerydynamic-html

How to change html shorthand to html tag when adding content dynamically


var encodedHtml = "<ol style="color: rgb(34, 34, 34); font-family: arial, sans-serif;"><li class="mod" style=""> <div class="_oDd" style=""><span class="_Tgc" style="font-size: 16px;"><b>Test data</b> is <b>data</b>

which has been specifically identified for use in <b>tests</b>, typically of a computer program. Some <b>data</b> may be used in a confirmatory way, typically to verify that a given set of input to a given function produces some expected result.</span></div> </li></ol>";

I want to change this content to html tags , so i can add it to some div using js.


Solution

  • This should get you sorted out:

    What's the right way to decode a string that has special HTML entities in it?

    A few answers down it has a jQuery version:

    function htmlDecode(value) {
        return $("<textarea/>").html(value).text();
    }