Is it possible to get the createTextNode method to render html tags?

前端 未结 1 1478
暖寄归人
暖寄归人 2020-12-10 16:37

The following code prints

This should print(b)This should print(/b)This should print



        
相关标签:
1条回答
  • 2020-12-10 17:02

    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.

    0 讨论(0)
提交回复
热议问题