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!
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!
As if the string is a HTML entity, you can use jQuery.parseHTML()
like this:
var element = $.parseHTML("<p>Something</p>");
Hope this helps!
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 -->
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>