Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions ex.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<title>DOM data types - element</title>
</head>
<body>
<div id="wrapperForChildren">
<script id="function_getChildrenOf">
function getChildrenOf(elementId) {
let children = document.getElementById(elementId).children;
let elementsString = "";
for (let index = 0; index < children.length; index++) {
let element = children[index];
grandChildren = element.children;
console.log("grandChildren.length ", grandChildren.length);
elementsString += `tag: ${element.tagName}, id: ${element.id}<br>`;
for (let index = 0; index < grandChildren.length; index++) {
const grandChild = grandChildren[index];
elementsString += `tag: ${grandChild.tagName}, id: ${grandChild.id}<br>`;
}
}
document.getElementById("childrenSample").innerHTML = elementsString;
}
</script>

<h2 id="h2_children">children</h2>
<div id="childrenSampleDiv">
<p id="childrenSample"></p>
<button onclick="getChildrenOf('wrapperForChildren')">
show children
</button>
</div>
</div>
</body>
</html>