I have an element is called divElement
:
<div ....>
</div>
and I have p
element is called 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:
<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)
Simply concatenate the sign with the innerHTML of the div.
HTML :
<div id="divElement">
<p id="pElement">
Hello
</p>
</div>
javaScript :
var element = document.getElementById("divElement");
element.innerHTML += "▽";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.