Title1

Title2

Title3

7-3 Element.insertAdjacentHTML()

參考:https://developer.mozilla.org/zh-TW/docs/Web/API/Element/insertAdjacentHTML

Element.insertAdjacentHTML()

insertAdjacentHTML() 把傳入的字串解析成 HTML 或 XML,並把該節點插入到 DOM 樹指定的位置。它不會重新解析被使用的元素,因此他不會破壞該元素裡面原有的元素。這避免了序列化的複雜步驟,使得它比直接操作 innerHTML 快上許多。

Parameters

position

DOMString representing the position relative to the element; must be one of the following strings: 

  • 'beforebegin': 在 element 之前。
  • 'afterbegin': 在 element 裡面,第一個子元素之前。
  • 'beforeend': 在 element 裡面,最後一個子元素之後。
  • 'afterend': 在 element 之後。
text

text 是即將被解析並插入到 DOM 樹裡的字串。