Javascript innerHTML vs outerHTML

后端 未结 3 416
忘掉有多难
忘掉有多难 2021-01-03 23:24

I have the following javascript:

// create a new article tag
var elem = document.createElement(\'article\');

// append the article to the comments list
docu         


        
3条回答
  •  半阙折子戏
    2021-01-03 23:31

    According to the OP questions, its comments, and the one good answer, in this instance you are better off using elem.outerHTML because you are/can pre-parse your input in Rails.

    If you were to move decision making to the JavaScript side, good coding practice would dictate creating all nodes by hand. If you are processing 100's of element inserts then you will notice a difference in speed (if you were to benchtest both solutions).

提交回复
热议问题