HTML DOM метод insertAdjacentText()
Пример
Вставьте текст после указанного элемента заголовка:
var h = document.getElementById("myH2");
h.insertAdjacentText("afterend",
"My inserted text");
Определение и использование
Метод insertAdjacentText()
вставляет указанный элемент в указанную позицию.
Значения юридического положения:
"после начала"
"после окончания"
"до начала"
"до конца"
Поддержка браузера
Цифры в таблице указывают на первую версию браузера, полностью поддерживающую метод.
Method | |||||
---|---|---|---|---|---|
insertAdjacentText() | Yes | Yes | 48 | Yes | Yes |
Синтаксис
node.insertAdjacentText(position, text)
Значения параметров
Parameter | Type | Description |
---|---|---|
position | String | Required. A position relative to the element. Legal values: "afterbegin" - After the beginning of the element (as the first child) "afterend" - After the element "beforebegin" - Before the element "beforeend" - Before the end of the element (as the last child) |
text | String | The text you want to insert |
Дополнительные примеры
Пример
Используя значение «после начала»:
var h = document.getElementById("myH2");
h.insertAdjacentText("afterbegin",
"My inserted text");
Пример
Используя значение «beforebegin»:
var h = document.getElementById("myH2");
h.insertAdjacentText("beforebegin",
"My inserted text");
Пример
Используя значение «до конца»:
var h = document.getElementById("myH2");
h.insertAdjacentText("beforeend",
"My inserted text");