[英]Insert html (unicode text) after an element
I have an element is called divElement
: 我有一个元素叫做
divElement
:
<div ....>
</div>
and I have p
element is called pElement
: 我有
p
元素称为pElement
:
<p ....>
</p>
I did: 我做了:
divElement.appendChild(pElement);
and I got new element: 我有了新的元素:
<div ....>
<p ....>
</p>
</div>
now I want to add this unicode text (▽) after the p element in order to get: 现在我想在p元素之后添加此unicode文本(▽),以获得:
<div ....>
<p ....>
</p>
▽
</div>
I tried: 我试过了:
divElement.innerHTML = "▽";
but I got: 但是我得到了:
<div ....>
▽
<p ....>
</p>
</div>
any help appreciated! 任何帮助表示赞赏!
You could do this: 您可以这样做:
divElement.appendChild(document.createTextNode("▽"))
Or, if you don't want to include the literal character: 或者,如果您不想包含文字字符:
var charDiv = document.createElement('div')
charDiv.innerHTML = "▽"
document.body.appendChild(charDiv)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.