appendChild
When moving elements, you need to associate the element you want to move with its new parent.
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
</head>
<body>
<table border="1">
<tbody>
<tr><td>A</td><td>B</td></tr>
<tr id="apple"><td>C</td><td>D</td></tr>
</tbody>
</table>
<br/>
<table border="1">
<tbody id="SurveysBody">
<tr><td>E</td><td>F</td></tr>
</tbody>
</table>
<p>
<button id="move">Move Row</button>
</p>
<script>
document.getElementById("move").onclick = function() {
var elem = document.getElementById("apple");
document.getElementById("SurveysBody").appendChild(elem);
};
</script>
</body>
</html>
Home
JavaScript Book
DOM
JavaScript Book
DOM
HTMLElement:
- The HTMLElement Members
- element tag name, id, direction, language, hidden disabled information
- addEventListener
- appendChild
- attributes returns a collection containing all of the attributes
- classList
- className
- cloneNode
- createElement
- createTextNode
- dataset
- getAttribute
- getElementsByTagName
- hasAttribute
- innerHTML
- insertAdjacentHTML
- insertBefore
- isSameNode
- outerHTML
- onmouseout
- onmouseover
- querySelectorAll
- removeEventListener