xxxxxxxxxx
// Accessing and printing child nodes
const parentElement = document.getElementById('parent'); // replace 'parent' with the actual id of the parent element
// Iterate over child nodes using a for loop
for (let i = 0; i < parentElement.childNodes.length; i++) {
const childNode = parentElement.childNodes[i];
console.log('Child Node:', childNode);
}
// Alternatively, iterate over child nodes using forEach
parentElement.childNodes.forEach(childNode => {
console.log('Child Node:', childNode);
});
xxxxxxxxxx
<!DOCTYPE html>
<html>
<body>
<h1>The Element Object</h1>
<h2>The children Property</h2>
<p>The tag names of the body's children are:</p>
<p id="demo"></p>
<script>
const collection = document.body.children;
let text = "";
for (let i = 0; i < collection.length; i++) {
text += collection[i].tagName + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
xxxxxxxxxx
console.log('In Child.js')
// If the send method is available
if (process.connected) {
// Send multiple messages
setTimeout((function () {
if (process.connected == true) {
console.log("This was sent after 1 second.");
}
}), 1000);
setTimeout((function () {
if (process.connected == true) {
console.log("This was sent after 2 seconds.");
}
}), 2000);
// Disconnect after 2.5 seconds
setTimeout((function () {
process.disconnect();
}), 2500);
setTimeout((function () {
if (process.connected == true) {
console.log("This was sent after 3 seconds.");
}
}), 3000);
}