--- title: ParentNode.append() slug: Web/API/ParentNode/append translation_of: Web/API/ParentNode/append ---
{{APIRef("DOM")}}

El método ParentNode.append() inserta un conjunto de objetos de tipo {{domxref("Node")}} u objetos de tipo {{domxref("DOMString")}} después del último hijo de ParentNode. Los objetos {{domxref("DOMString")}} son insertados como nodos {{domxref("Text")}} equivalentes.

Diferencias con {{domxref("Node.appendChild()")}}:

Sintaxis

[Throws, Unscopable]
void ParentNode.append((Node or DOMString)... nodes);

Parameters

nodes
Un conjunto de {{domxref("Node")}} u objetos {{domxref("DOMString")}} a agegar.

Exceptions

Examples

Appending an element

var parent = document.createElement("div");
var p = document.createElement("p");
parent.append(p);

console.log(parent.childNodes); // NodeList [ <p> ]

Appending text

var parent = document.createElement("div");
parent.append("Some text");

console.log(parent.textContent); // "Some text"

Appending an element and text

var parent = document.createElement("div");
var p = document.createElement("p");
parent.append("Some text", p);

console.log(parent.childNodes); // NodeList [ #text "Some text", <p> ]

ParentNode.append() is unscopable

The append() method is not scoped into the with statement. See {{jsxref("Symbol.unscopables")}} for more information.

var parent = document.createElement("div");

with(parent) {
  append("foo");
}
// ReferenceError: append is not defined 

Polyfill

You can polyfill the append() method in Internet Explorer 9 and higher with the following code:

// Source: https://github.com/jserz/js_piece/blob/master/DOM/ParentNode/append()/append().md
(function (arr) {
  arr.forEach(function (item) {
    if (item.hasOwnProperty('append')) {
      return;
    }
    Object.defineProperty(item, 'append', {
      configurable: true,
      enumerable: true,
      writable: true,
      value: function append() {
        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.appendChild(docFrag);
      }
    });
  });
})([Element.prototype, Document.prototype, DocumentFragment.prototype]);

Specification

Specification Status Comment
{{SpecName('DOM WHATWG', '#dom-parentnode-append', 'ParentNode.append()')}} {{Spec2('DOM WHATWG')}} Initial definition.

Browser compatibility

{{Compat("api.ParentNode.append")}}

See also