I'm trying to do the following:
$.getJSON("script/course_session.php", data, function(data) {
$.each(data, function(i, item) {
var $tr = $('<tr>').append(
$('<td>').text(item.start_date + " - " + item.end_date),
$('<td>').text(
'<div class="col-md-3 btn-buy animated fadeInRight"><a href="#" class="btn-u btn-u-sm enroll-button"><i class="fa fa-university"></i> Register</a></div>')
).appendTo("#session-table");
});
});
The intent being to achieve something like the following (I'm using Bootstrap):
However, this is how it gets printed:
What is the correct way to render html?
You have to use .html(...) instead of .text(). And " instead of quot;
A string of HTML to set as the content of each matched element.
The text to set as the content of each matched element. When Number or Boolean is supplied, it will be converted to a String representation.
The difference is the .html(str)
will convert str
the to a DOM if the str
have a tag content and the .text()
must convert str
to a text even if str
contains XML or html.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.