http://blog.hompy.info/439

자바스크립트 createElement, insertBefore, replaceChild, appendChild 다루기 샘플
<html>
<div id = "a">
<div id=a1>&lt;div&gt;a1&lt;/div&gt;</div>
<div id=a2>&lt;div&gt;a2&lt;/div&gt;</div>
<div id=a3>&lt;div&gt;a3&lt;/div&gt;</div>
<div id=a4>&lt;div&gt;a4&lt;/div&gt;</div>
<div id=a5>&lt;div&gt;a5&lt;/div&gt;</div>
</div>
<script>
newobj = d0cument.createElement( "div");
newobj.innerHTML = '&lt;div&gt;b&lt;/div&gt;';
newobj2 = d0cument.createElement( "div");
newobj2.innerHTML = '&lt;div&gt;c&lt;/div&gt;';
divobjs = d0cument.getElementsByTagName( "div");
//divobjs[2].parentNode.appendChild( newobj);

d0cument.getElementById('a').insertBefore(d0cument.getElementById('a3'), d0cument.getElementById('a2'));
d0cument.getElementById('a').replaceChild(newobj, d0cument.getElementById('a3'));
d0cument.getElementById('a').appendChild(newobj2);

//alert(d0cument.getElementById('a').innerHTML);
</script>
</html>

<div>a1</div>
<div>b</div>
<div>a2</div>
<div>a4</div>
<div>a5</div>
<div>c</div>
Posted by 퓨전마법사
,