The following code prints
This should print(b)This should print(/b)This should print
<script>
function produceMessage(){
var msg= '<b>This should print</b>';
return msg;
}
</script>
<span id="mySpan"></span>
<script>
document.body.appendChild(document.createTextNode(produceMessage()));
document.write(produceMessage());
document.getElementById('mySpan').innerHTML=produceMessage();
</script>
No, a text node will not print any HTML. Instead, create an element, or use a document fragment to insert HTML in that way.
function boldHTML() {
var element = document.createElement("b");
element.innerHTML = "Bold text";
return element;
}
document.body.appendChild(boldHTML());
will print Bold text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With