javascript innerHTML adding instead of replacing

前端 未结 6 1555
名媛妹妹
名媛妹妹 2020-11-30 04:32

quick question, i know we can change the content of a

hello one
by using:

docum         


        
6条回答
  •  误落风尘
    2020-11-30 05:19

    What jcomeau_ictx suggested is an inefficient way of editing the innerHTML. Check Ben cherry's PPT http://www.bcherry.net/talks/js-better-faster

    The correct way will be detaching the element and making changes to it and then appending it back to the parent node. Use https://gist.github.com/cowboy/938767 Native javascript from this gist to detach element.

提交回复
热议问题