From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- .../web/api/element/insertadjacenthtml/index.html | 138 +++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 files/pt-br/web/api/element/insertadjacenthtml/index.html (limited to 'files/pt-br/web/api/element/insertadjacenthtml/index.html') diff --git a/files/pt-br/web/api/element/insertadjacenthtml/index.html b/files/pt-br/web/api/element/insertadjacenthtml/index.html new file mode 100644 index 0000000000..89a0bbdfcc --- /dev/null +++ b/files/pt-br/web/api/element/insertadjacenthtml/index.html @@ -0,0 +1,138 @@ +--- +title: Element.insertAdjacentHTML() +slug: Web/API/Element/insertAdjacentHTML +translation_of: Web/API/Element/insertAdjacentHTML +--- +
{{APIRef("DOM")}}
+ +

Resumo

+ +

insertAdjacentHTML analisa o texto especificado como HTML ou XML e insere os nós que resultam na árvore DOM em uma posição especificada. Não reanalisa o elemento que está a ser utilizado e, portanto, não corrompe os elementos existentes dentro do elemento. Esta, e evitando a etapa extra de serialização, torna-o muito mais rápido do que a manipulação direta innerHTML.

+ +

Sintaxe

+ +
element.insertAdjacentHTML(posição, texto);
+ +

Posição é a posição em relação ao elemento, e deve ser um dos seguintes tipos:

+ +
+
'beforebegin'
+
Antes do elemento.
+
'afterbegin'
+
Dentro do elemento, antes de seu primeiro filho (childNode).
+
'beforeend'
+
Dentro do elemento, após seu último filho (childNode) .
+
'afterend'
+
Após o elemento.
+
+ +

texto é a string a ser analisada como HTML ou XML e inserido na árvore.

+ +

Visualização da posição de nomes

+ +
<!-- beforebegin -->
+<p>
+<!-- afterbegin -->
+foo
+<!-- beforeend -->
+</p>
+<!-- afterend -->
+ +
Nota:  As posições beforeBegin e afterEnd funcionam apenas se o nó está em uma árvore DOM e tem um elemento pai.
+ +

Exemplo

+ +
// Estrutura inicial:
+// <div id="one">one</div>
+
+var d1 = document.getElementById('one');
+d1.insertAdjacentHTML('afterend', '<div id="two">two</div>');
+
+// Neste ponto, a nova estrutura é:
+// <div id="one">one</div>
+// <div id="two">two</div>
+ +

Especificação

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('DOM Parsing', '#insertadjacenthtml()', 'Element.insertAdjacentHTML()')}}{{ Spec2('DOM Parsing') }} 
+ +

Compatibilidade de Navegadores

+ +

{{ CompatibilityTable() }}

+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Suporte básico1.0{{ CompatGeckoDesktop("8.0") }}4.0*7.04.0 (527)
+
+ +
+ + + + + + + + + + + + + + + + + + + +
 CaracterísticaAndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Suporte básico{{ CompatUnknown() }}{{ CompatGeckoMobile("8.0") }}{{ CompatUnknown() }}{{ CompatUnknown() }}{{ CompatUnknown() }}
+ +

 

+ +

Questão no IE:

+ + +
+ +

Veja também

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