Reputation: 979
I got following json:
{"results":[{"id":"1","title":"Hello","content":"Hello<br>world"}]}
the data can be successfully displayed in the following way
$('<td class="a">').html(res.id),
$('<td class="b">').html(res.title),
$('<td class="c">').html(res.content),
The only problem is that I want to display <br>
tag as well. Is there any function in jquery which can help me to display html tag as well?
Upvotes: 0
Views: 293
Reputation: 288120
Yes, you can use text
:
We need to be aware that this method escapes the string provided as necessary so that it will render correctly in HTML. To do so, it calls the DOM method
.createTextNode()
, does not interpret the string as HTML.
$('<td class="a">').text(res.id);
$('<td class="b">').text(res.title);
$('<td class="c">').text(res.content);
Upvotes: 2