From 0ccebc7eb352eda4d26d0b876fea36f24f482eec Mon Sep 17 00:00:00 2001 From: MDN Date: Sat, 17 Apr 2021 00:11:36 +0000 Subject: [CRON] sync translated content --- .../orphaned/web/api/parentnode/append/index.html | 135 +++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 files/es/orphaned/web/api/parentnode/append/index.html (limited to 'files/es/orphaned/web/api/parentnode') diff --git a/files/es/orphaned/web/api/parentnode/append/index.html b/files/es/orphaned/web/api/parentnode/append/index.html new file mode 100644 index 0000000000..4944a7fe68 --- /dev/null +++ b/files/es/orphaned/web/api/parentnode/append/index.html @@ -0,0 +1,135 @@ +--- +title: ParentNode.append() +slug: orphaned/Web/API/ParentNode/append +translation_of: Web/API/ParentNode/append +original_slug: 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

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('DOM WHATWG', '#dom-parentnode-append', 'ParentNode.append()')}}{{Spec2('DOM WHATWG')}}Initial definition.
+ +

Browser compatibility

+ + + +

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

+ +

See also

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