Remove child nodes (or elements) or set innerHTML=“”?

后端 未结 3 1151
鱼传尺愫
鱼传尺愫 2021-01-18 21:27

When clearing HTML elements such as select boxes, tables, or lists, is it better/faster to remove the nodes (e.g., select.options.remove(i), table.deleteR

3条回答
  •  隐瞒了意图╮
    2021-01-18 21:39

    Per this conversation here: What is the best way to empty an node in JavaScript

    It appears that the while (elm.firstChild) {elm.removeChild(elm.firstChild);} approach got the the best results across browsers in this test.

    (Would have put this as a comment instead of an answer, but the comments are coming in awful fast, so I didn't want it to get lost.)

提交回复
热议问题