DOM结构操作
var div1 = document.getElementById('div1');
var p1 = document.createElement('p');
p1.innerHTML = 'this is p1';
div1.appendChild(p1);
var p2 = document.getElementById('p2');
div1.appendChild(p2);
var div1 = document.getElementById('div1');
var parent = div1.parentElement;
var div1 = document.getElementById('div1');
var child = div1.childNodes;
div1.removeChild(child[0]);
举个栗子(例子:example)!!!
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="div1">
<p id="p1">this is p1</p>
<p id="p2">this is p2</p>
</div>
<div id="div2">
<p id="p3">this is p3</p>
<p id="p4">this is p4</p>
</div>
<script type="text/javascript">
var p4 = document.getElementById('p4');
var div1 = document.getElementById('div1');
div1.appendChild(p4);
console.log(p4.parentElement);
console.log(div1.parentElement);
console.log(div1.childNodes);
console.log(div1.childNodes[0].nodeType);
console.log(div1.childNodes[1].nodeType);
</script>
</body>
</html>