childNodes
returns an array of an element's child nodes.
JSfunction setText() {
let a = document.getElementById("demo");
let arr = a.childNodes;
for(let x=0;x<arr.length;x++) {
arr[x].innerHTML = "new text";
}
}
//calling the function with setTimeout to make sure the HTML is loaded
setTimeout(setText, 500);
HTML of the example<div id ="demo">
<p>some text</p>
<p>some other text</p>
</div>
Note: The code above changes the text of both paragraphs to new text