Adding new elements into DOM using JavaScript (appendChild)

后端 未结 4 1565
[愿得一人]
[愿得一人] 2021-01-05 04:03

I sometimes need to add elements (such as a new link and image) to an existing HTML page, but I only have access to a small portion of the page far from where I need to inse

4条回答
  •  情话喂你
    2021-01-05 04:43

    There is a more efficient way, and seems to be using documentFragments if possible. Check it out: http://ejohn.org/blog/dom-documentfragments/ . Also this way should be less error prone and more maintainable than starting to mix up huge strings literals and setting them as innerHTML of some other DOM objects.

提交回复
热议问题