create/append node vs innerHTML

后端 未结 7 2192
情歌与酒
情歌与酒 2021-01-05 18:40

Does anyone have a good reason to use one over the other? As far as I can tell, create/append node simply prevents you from creating invalid code, while innerHTML allows you

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-05 19:12

    This is always a contentious argument, partially because the origin of innerHTML being somewhat dubious from a standards perspective. I think the QuirksMode article is still relevant, but I'd love to see it updated. Perhaps contact ppk about updating them, though I'm sure he's busy. We could all benefit from performance testing the assumptions we make in web development. In the end claims require hard data to prove, otherwise it's really just talk.

    Anyway, I did some searching and found some interesting articles relevant to this discussion. I don't remember hearing of DocumentFragments before, they're real interesting.

    • DOM DocumentFragments
    • jQuery Performance Rules
    • Improve your jQuery - 25 excellent tips
    • Speed test: innerHTML versus DOM manipulation ... a test that actually tests the speed, worth it for anyone who wants to collect some current data on browsers

提交回复
热议问题