You can remove text from a <div> in JavaScript using the following methods:
1. Set innerText or textContent to an empty string
document.getElementById("myDiv").innerText = "";
// OR
document.getElementById("myDiv").textContent = "";
2. Set innerHTML to an empty string (Removes all content including child elements)
document.getElementById("myDiv").innerHTML = "";
3. Remove only text nodes while keeping child elements
const div = document.getElementById("myDiv");
div.childNodes.forEach(node => {
if (node.nodeType === Node.TEXT_NODE) {
node.remove();
}
});