diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:17 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:17 -0500 |
| commit | da78a9e329e272dedb2400b79a3bdeebff387d47 (patch) | |
| tree | e6ef8aa7c43556f55ddfe031a01cf0a8fa271bfe /files/ko/web/api/node/replacechild | |
| parent | 1109132f09d75da9a28b649c7677bb6ce07c40c0 (diff) | |
| download | translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.gz translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.bz2 translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.zip | |
initial commit
Diffstat (limited to 'files/ko/web/api/node/replacechild')
| -rw-r--r-- | files/ko/web/api/node/replacechild/index.html | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/files/ko/web/api/node/replacechild/index.html b/files/ko/web/api/node/replacechild/index.html new file mode 100644 index 0000000000..b058cc4c99 --- /dev/null +++ b/files/ko/web/api/node/replacechild/index.html @@ -0,0 +1,71 @@ +--- +title: Node.replaceChild() +slug: Web/API/Node/replaceChild +tags: + - 노드 교체 + - 돔 조작 + - 자바스크립트 +translation_of: Web/API/Node/replaceChild +--- +<div> +<div>{{APIRef("DOM")}}</div> +</div> + +<p><strong><code>Node.replaceChild()</code></strong> 메소드는 특정 부모 노드의 한 자식 노드를 다른 노드로 교체합니다.</p> + +<h2 id="Syntax" name="Syntax">Syntax</h2> + +<pre class="syntaxbox"><em>replacedNode</em> = <em>parentNode</em>.replaceChild(<em>newChild</em>, <em>oldChild</em>); +</pre> + +<ul> + <li><code>newChild는 oldChild를 교체할 새로운 노드입니다. 만약 이미 </code>DOM<code> 안에 존재한다면 가장 먼저 제거됩니다.</code></li> + <li><code>oldChild는 이미 존재하는, 교체될 자식 노드입니다.</code></li> + <li><code>replacedNode는 교체된 노드입니다. oldChild와 동일한 노드입니다.</code></li> +</ul> + +<h2 id="Example" name="Example">Example</h2> + +<pre class="brush:js">// <div> +// <span id="childSpan">foo bar</span> +// </div> + +// 텅빈 요소 노드를 하나 생성합니다. +// ID도, 속성도, 컨텐츠도 없습니다. +var sp1 = document.createElement("span"); + +// 'newSpan'이란 id 속성을 부여합니다. +sp1.id = "newSpan"; + +// 새로운 요소를 위한 컨텐츠를 생성합니다. +var sp1_content = document.createTextNode("new replacement span element."); + +// 컨텐츠를 생성한 요소에 붙입니다. +sp1.appendChild(sp1_content); + +// DOM에 존재하던, 교체되야할 노드를 참조합니다. +var sp2 = document.getElementById("childSpan"); +var parentDiv = sp2.parentNode; + +// 이미 존재하던 sp2 노드를 새로운 span 요소인 sp1으로 교체합니다. +parentDiv.replaceChild(sp1, sp2); + +// 결과: +// <div> +// <span id="newSpan">new replacement span element.</span> +// </div> +</pre> + +<h2 id="Specification" name="Specification">Specification</h2> + +<ul> + <li><a href="http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#method-replaceChild">DOM Level 1 Core: replaceChild</a></li> + <li><a href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-785887307">DOM Level 2 Core: replaceChild</a></li> + <li><a href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-785887307">DOM Level 3 Core: replaceChild</a></li> +</ul> + +<h2 id="See_also" name="See_also">See also</h2> + +<ul> + <li>{{domxref("Node.removeChild")}}</li> +</ul> |
