Adding new elements into DOM using JavaScript (appendChild)

后端 未结 4 1567
[愿得一人]
[愿得一人] 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:45

    Nothing wrong with that. Using innerHTML would be marginally faster and probably fewer characters but not noticeable for something of this scale, and my personal preference is for the more standard, uniformly supported and safer DOM methods and properties.

    One minor point: the height and width properties of elements should be numbers rather than strings.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题