Appending HTML-encoded string as HTML, not as text

前端 未结 3 1515
野的像风
野的像风 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:01

    You can create a new div with .createElement('div'). Then simply change the new element's HTML.

    $(document.createElement('div').html('

    All new content.

    '));

    To attach the new element to the DOM either use element.append() or .appendTo(element) to append to your element of choice.

提交回复
热议问题