我试图追加这个字符串:
- <div> hello </div>
作为HTML节点,而不是附加HTML,它只是附加文本:
- <div> hello </div>
如何使jQuery将其作为HTML节点附加,而不仅仅是文本?
我想要一个可以用于嵌套div和文本的解决方案.
解决方法
- // 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);