zak*_*ces 14 html javascript jquery append
我正在尝试追加这个字符串:
<div> hello </div>
Run Code Online (Sandbox Code Playgroud)
作为HTML节点,但它不是附加HTML而只是附加文本:
<div> hello </div>
Run Code Online (Sandbox Code Playgroud)
如何让jQuery将其作为HTML节点附加,而不仅仅是文本?
如果可能的话,我想要一个适用于嵌套div和文本的解决方案.
Tim*_*uri 23
// This is your string :)
var myString = "<div> hello </div>";
// This is a way to "htmlDecode" your string... see link below for details.
myString = $("<div />").html(myString).text();
// This is appending the html code to your div (which you don't have an ID for :P)
$("#TheDivIWantToChange").append(myString);
Run Code Online (Sandbox Code Playgroud)