From de5c456ebded0e038adbf23db34cc290c8829180 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:49:24 +0100 Subject: unslug pl: move --- files/pl/web/api/node/insertbefore/index.html | 86 +++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 files/pl/web/api/node/insertbefore/index.html (limited to 'files/pl/web/api/node/insertbefore') diff --git a/files/pl/web/api/node/insertbefore/index.html b/files/pl/web/api/node/insertbefore/index.html new file mode 100644 index 0000000000..27c40ad945 --- /dev/null +++ b/files/pl/web/api/node/insertbefore/index.html @@ -0,0 +1,86 @@ +--- +title: element.insertBefore +slug: Web/API/Element/insertBefore +tags: + - DOM + - Dokumentacja_Gecko_DOM + - Gecko + - Wszystkie_kategorie +translation_of: Web/API/Node/insertBefore +--- +

{{ ApiRef() }}

+ +

Podsumowanie

+ +

Wstawia określony węzeł przed danym elementem jako dziecko aktualnego węzła.

+ +

Składnia

+ +
var wstawionyElement =elementRodzic.insertBefore(nowyElement,danyElement)
+
+ +

Jeżeli danyElement ma wartość null, nowyElement jest wstawiany na końcu listy węzłów potomnych.

+ + + +

Przykład

+ +
 <html>
+
+ <head>
+ <title>Gecko DOM insertBefore test</title>
+ </head>
+
+ <body>
+ <div>
+   <span id="childSpan">foo bar</span>
+ </div>
+
+ <script type="text/javascript">
+ // tworzy pusty węzeł elementu
+ // bez ID, jakichkolwiek atrybutów lub jakiejkolwiek zawartości
+ var sp1 = document.createElement("span");
+
+ // daje to atrybut id nazwany 'newSpan'
+ sp1.setAttribute("id", "newSpan");
+
+ // tworzy jakąś zawartość dla nowo powstałego elementu.
+ var sp1_content = document.createTextNode("Jest to nowy element span. ");
+
+ // zwraca się, która treść ma być do nowego elementu.
+ sp1.appendChild(sp1_content);
+
+ var sp2 = document.getElementById("childSpan");
+ var parentDiv = sp2.parentNode;
+
+ // wstawia nowy element do DOM przed sp2
+ parentDiv.insertBefore(sp1, sp2);
+ </script>
+
+ </body>
+ </html>
+
+ +

Nie istnieje metoda insertAfter, jednak można ją emulować poprzez kombinację insertBefore oraz nextSibling.

+ +

W powyższym przykładzie, sp1 może zostać wstawiona za sp2 przy użyciu:

+ +
parentDiv.insertBefore(sp1, sp2.nextSibling);
+
+ +

Jeżeli sp2 nie posiada następnego rodzeństwa i musi być ostatnim potomnym —sp2.nextSibling to zwróci null więc sp1 będzie wstawione na końcu listy węzłów potomnych (np. natychmiast po sp2).

+ +

Specyfikacja

+ +

insertBefore

+ +

 

+ +
 
+ +

{{ languages( { "en": "en/DOM/element.insertBefore", "fr": "fr/DOM/element.insertBefore", "ja": "ja/DOM/element.insertBefore", "pt": "pt/DOM/element.insertBefore" } ) }}

-- cgit v1.2.3-54-g00ecf