xxxxxxxxxx
<!DOCTYPE html>
<html>
<body>
<p id="name1">Apple</p>
<p id="name2">Orange</p>
<p id="name3">Mango</p>
<script>
let text_content = document.querySelector("#name1").textContent;
let inner_text = document.querySelector("#name2").innerText;
let inner_html = document.querySelector("#name3").innerHTML;
console.log(text_content);
console.log(inner_text);
console.log(inner_html);
/*output:
Apple
Orange
Mango
*/
</script>
</body>
</html>
xxxxxxxxxx
<p id="paragraph">Hello world!</p>
<script type="text/javascript">
const element = document.getElementById("paragraph");
// The `textContent` property of `HTMLElement`s allows
// you to get and set the visible text of a `HTMLElement`.
console.log(element.textContent);
element.textContent = "A new string...";
console.log(element.textContent);
</script>