Appending HTML-encoded string as HTML, not as text

前端 未结 3 1518
野的像风
野的像风 2020-12-10 12:21

I\'m trying to append this string:

<div> hello </div>

as an HTML node, but instead of appending HTML it just ap

3条回答
  •  鱼传尺愫
    2020-12-10 13:11

    Maybe this is a bit verbose, but this is usually how I handle stuff like that:

    var div = $(document.createElement("div"));
    
    div.text(" hello "); //Or div.html(" hello ") if need be...
    
    $("#divtoappendto").append(div);
    

提交回复
热议问题