-1

I have a column in a DB which has the value:

<p>Something</p>

When i receive it, how do i transform it in a html paragraph? Thanks!

  • 2
    that _is_ a paragraph. – Moob Dec 02 '16 at 15:43
  • 1
    What language are you using? What have you tried? How is it not already an HTML paragraph? Please clarify your question. – Jorick Spitzen Dec 02 '16 at 15:43
  • Possible duplicate of [How do you use $sce.trustAsHtml(string) to replicate ng-bind-html-unsafe in Angular 1.2+](http://stackoverflow.com/questions/18340872/how-do-you-use-sce-trustashtmlstring-to-replicate-ng-bind-html-unsafe-in-angu) – Daniel Corzo Dec 02 '16 at 15:46

3 Answers3

1

As if the string is a HTML entity, you can use jQuery.parseHTML() like this:

var element = $.parseHTML("<p>Something</p>");

Hope this helps!

Saumya Rastogi
  • 13,159
  • 5
  • 42
  • 45
1

var stringInDB = '<p>Something</p>'; //get the string
$('#target').html(stringInDB);       //set the content (the string as html) of the elemtn where you want to put that string
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="target"> <div/> <!-- where you want to put you string as html -->
Jamiec
  • 133,658
  • 13
  • 134
  • 193
lealceldeiro
  • 14,342
  • 6
  • 49
  • 80
0

If you are using Angular (which it looks like from the tagging) you could always include ngSanitize and bind the scope element in your template:

<div ng-bind-html="ctrl.stringProperty">
  ...
</div>
sledsworth
  • 143
  • 1
  • 8