From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- files/ru/web/api/element/outerhtml/index.html | 148 ++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 files/ru/web/api/element/outerhtml/index.html (limited to 'files/ru/web/api/element/outerhtml') diff --git a/files/ru/web/api/element/outerhtml/index.html b/files/ru/web/api/element/outerhtml/index.html new file mode 100644 index 0000000000..525ac3573e --- /dev/null +++ b/files/ru/web/api/element/outerhtml/index.html @@ -0,0 +1,148 @@ +--- +title: Element.outerHTML +slug: Web/API/Element/outerHTML +tags: + - Парсинг + - Парсинг DOM + - Свойство + - Сериализация + - Ссылка +translation_of: Web/API/Element/outerHTML +--- +

{{APIRef("DOM")}}

+ +

Описание

+ +

Атрибут outerHTML DOM-интерфейса {{ domxref("element") }} получает сериализованный HTML-фрагмент, описывающий элемент, включая его потомков. Можно установить замену элемента узлами, полученными из заданной строки.

+ +

Синтаксис

+ +
var content = element.outerHTML;
+
+ +

На выводе, content содержит сериализованный HTML-фрагмент, описывающий element и его потомки.

+ +
element.outerHTML = content;
+
+ +

Replaces the element with the nodes generated by parsing the string content with the parent of element as the context node for the fragment parsing algorithm.

+ +

Примеры

+ +

Получение свойства outerHTML элемента:

+ +
// HTML:
+// <div id="d"><p>Content</p><p>Further Elaborated</p></div>
+
+d = document.getElementById("d");
+console.log(d.outerHTML);
+
+// строка '<div id="d"><p>Content</p><p>Further Elaborated</p></div>'
+// выведена в окно консоли
+
+ +

Замена ветки с помощью изменения свойства outerHTML:

+ +
// HTML:
+// <div id="container"><div id="d">Это div.</div></div>
+
+container = document.getElementById("container");
+d = document.getElementById("d");
+console.log(container.firstChild.nodeName); // логирует "DIV"
+
+d.outerHTML = "<p>Этот параграф заменил исходный div.</p>";
+console.log(container.firstChild.nodeName); // логирует "P"
+
+// div #d больше не часть дерева документа,
+// новый параграф заменил его.
+
+ +

Примечания

+ +

Если у элемента нет родительской ветки, которая не является корневой веткой документа, установка его свойства outerHTML выбросит исключение DOMException с кодом ошибки NO_MODIFICATION_ALLOWED_ERR. Например:

+ +
document.documentElement.outerHTML = "test";  // бросает DOMException
+
+ +

Also, while the element will be replaced in the document, the variable whose outerHTML property was set will still hold a reference to the original element:

+ +
var p = document.getElementsByTagName("p")[0];
+console.log(p.nodeName); // показывает: "P"
+p.outerHTML = "<div>Этот div заменил параграф.</div>";
+console.log(p.nodeName); // всё ещё "P";
+
+ +

Specification

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('DOM Parsing', '#outerhtml', 'Element.outerHTML')}}{{ Spec2('DOM Parsing') }}
+ +

Поддержка браузерами

+ +

{{ CompatibilityTable() }}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureFirefox (Gecko)ChromeInternet ExplorerOperaSafari
Basic support{{ CompatGeckoDesktop("11") }}0.24.071.3
+
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{ CompatVersionUnknown() }}{{ CompatGeckoMobile("11") }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}{{ CompatVersionUnknown() }}
+
+ +

See also

+ + -- cgit v1.2.3-54-g00ecf