How to inject html code using jquery? [duplicate]
I have a tag that I want to inject some html code... ...the html code is like this...
line:1 3spaces b4<br /><br />line:3 5spaces
b4<br /> 5spaces b4, line: 4
If I use .text inj开发者_StackOverflow中文版ect this code, it just shows text, but not the html code. I would like to convert it to a html code, how can I do so?? Thank you.
Use .html()
instead of .text()
Use .html()
instead of .text()
.
Try:
$('#divname').html("code");
Solve it,
I need have a var htmlCode first, to convert it to decode HTML code, and use the html function... ... Thank everyone.
var htmlCode = $("<p/>").html("line:1 3spaces b4<br /><br />line:3 5spaces b4<br /> 5spaces b4, line: 4").text();
$("#aaa").html(htmlCode);
精彩评论