diff options
Diffstat (limited to 'files/pt-br/orphaned/web/api/childnode/after')
-rw-r--r-- | files/pt-br/orphaned/web/api/childnode/after/index.html | 186 |
1 files changed, 186 insertions, 0 deletions
diff --git a/files/pt-br/orphaned/web/api/childnode/after/index.html b/files/pt-br/orphaned/web/api/childnode/after/index.html new file mode 100644 index 0000000000..8fa84d11ee --- /dev/null +++ b/files/pt-br/orphaned/web/api/childnode/after/index.html @@ -0,0 +1,186 @@ +--- +title: ChildNode.after() +slug: orphaned/Web/API/ChildNode/after +tags: + - API + - DOM + - Experimental + - Nó + - Referencia + - metodo +translation_of: Web/API/ChildNode/after +original_slug: Web/API/ChildNode/after +--- +<div>{{APIRef("DOM")}} {{SeeCompatTable}}</div> + +<p>The <code><strong>ChildNode</strong></code><strong><code>.after()</code></strong> method inserts a set of {{domxref("Node")}} or {{domxref("DOMString")}} objects in the children list of this <code>ChildNode</code>'s parent, just after this <code>ChildNode</code>. {{domxref("DOMString")}} objects are inserted as equivalent {{domxref("Text")}} nodes.</p> + +<h2 id="Sintaxe">Sintaxe</h2> + +<pre class="syntaxbox">[Throws, Unscopable] +void ChildNode.after((Node or DOMString)... nodes); +</pre> + +<h3 id="Parâmetros">Parâmetros</h3> + +<dl> + <dt><code>nós</code></dt> + <dd>A set of {{domxref("Node")}} or {{domxref("DOMString")}} objects to insert.</dd> +</dl> + +<h3 id="Exceções">Exceções</h3> + +<ul> + <li>{{domxref("HierarchyRequestError")}}: Nó não pode ser inserido até que seja especificado o ponto da hierarquia. </li> +</ul> + +<h2 id="Exemplos">Exemplos</h2> + +<h3 id="Inserindo_uum_elemento">Inserindo uum elemento</h3> + +<pre class="brush: js">var parente = document.createElement("div"); +var filho = document.createElement("p"); +parente.appendChild(filho); +var span = document.createElement("span"); + +filho.after(span); + +console.log(parente.outerHTML); +// "<div><p></p><span></span></div>" +</pre> + +<h3 id="Inserindo_texto">Inserindo texto</h3> + +<pre class="brush: js">var parente = document.createElement("div"); +var filho = document.createElement("p"); +parente.appendChild(filho); + +filho.after("Text"); + +console.log(parente.outerHTML); +// "<div><p></p>Text</div>"</pre> + +<h3 id="Inserindo_um_elemento_e_um_texto">Inserindo um elemento e um texto </h3> + +<pre class="brush: js">var parente = document.createElement("div"); +var filho = document.createElement("p"); +parente.appendChild(filho); +var span = document.createElement("span"); + +filho.after(span, "Text"); + +console.log(parente.outerHTML); +// "<div><p></p><span></span>Text</div>"</pre> + +<h3 id="ChildNode.after()_is_unscopable"><code>ChildNode.after()</code> is unscopable</h3> + +<p>The <code>after()</code> method is not scoped into the <code>with</code> statement. Veja {{jsxref("Symbol.unscopables")}} para maior infomação.</p> + +<pre class="brush: js">with(node) { + after("foo"); +} +// ReferenceError: after is not defined </pre> + +<h2 id="Polyfill">Polyfill</h2> + +<p>Você pode usar polyfill com o método <code> after() </code> no Internet Explorer 9 e com o seguinte código:</p> + +<pre class="brush: js">//from: https://github.com/jserz/js_piece/blob/master/DOM/ChildNode/after()/after().md +(function (arr) { + arr.forEach(function (item) { + if (item.hasOwnProperty('after')) { + return; + } + Object.defineProperty(item, 'after', { + configurable: true, + enumerable: true, + writable: true, + value: function after() { + var argArr = Array.prototype.slice.call(arguments), + docFrag = document.createDocumentFragment(); + + argArr.forEach(function (argItem) { + var isNode = argItem instanceof Node; + docFrag.appendChild(isNode ? argItem : document.createTextNode(String(argItem))); + }); + + this.parentNode.insertBefore(docFrag, this.nextSibling); + } + }); + }); +})([Element.prototype, CharacterData.prototype, DocumentType.prototype]);</pre> + +<h2 id="_Polyfill_Element.prototype.after" name="_Polyfill_Element.prototype.after"> </h2> + +<pre class="brush: js">//https://github.com/FabioVergani/js-Polyfill_Element.prototype.after/blob/master/after.js + +(function(x){ + var o=x.prototype,p='after'; + if(!o[p]){ + o[p]=function(){ + var e, m=arguments, l=m.length, i=0, t=this, p=t.parentNode, n=Node, s=String, d=document; + if(p!==null){ + while(i<l){ + e=m[i]; + if(e instanceof n){ + t=t.nextSibling; + if(t!==null){ + p.insertBefore(e,t); + }else{ + p.appendChild(e); + }; + }else{ + p.appendChild(d.createTextNode(s(e))); + }; + ++i; + }; + }; + }; + }; +})(Element); + + + +/* +min: + +(function(x){ + var o=x.prototype; + o.after||(o.after=function(){var e,m=arguments,l=m.length,i=0,t=this,p=t.parentNode,n=Node,s=String,d=document;if(p!==null){while(i<l){((e=m[i]) instanceof n)?(((t=t.nextSibling )!==null)?p.insertBefore(e,t):p.appendChild(e)):p.appendChild(d.createTextNode(s(e)));++i;}}}); +}(Element)); + +*/ +</pre> + +<h3 id="sect1"> </h3> + +<h2 id="Especificação">Especificação</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Especificação</th> + <th scope="col">Status</th> + <th scope="col">Comentário</th> + </tr> + <tr> + <td>{{SpecName('DOM WHATWG', '#dom-childnode-after', 'ChildNode.after()')}}</td> + <td>{{Spec2('DOM WHATWG')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Compatibilidade com navegadores</h2> + +<p>{{Compat("api.ChildNode.after")}}</p> + +<h2 id="Veja_mais">Veja mais</h2> + +<ul> + <li>{{domxref("ChildNode")}} and {{domxref("ParentNode")}}</li> + <li>{{domxref("ChildNode.before()")}}</li> + <li>{{domxref("ParentNode.append()")}}</li> + <li>{{domxref("Node.appendChild()")}}</li> + <li>{{domxref("NodeList")}}</li> +</ul> |