<!-- Comment 1 -->
Only text
<!-- End -->
<p>Second text</p>
<br>
<button onclick="example()">Click me</button>
<br>
<button onclick="writeText()">Write in TEXT_NODE</button>
function example() {
  var bodyChildren = document.body.childNodes;
  var len = bodyChildren.length;

  console.clear();

  for (var i = 0; i < len; ++i) {
    console.log("nodeType - %s \t nodeValue - %s \t data - %s", bodyChildren[i].nodeType, bodyChildren[i].nodeValue, bodyChildren[i].data);
  }
}

/* Изменим значение текстовых узлов */
function writeText() {
  var bodyChildren = document.body.childNodes;
  var len = bodyChildren.length;

  console.clear();

  for (var i = 0; i < len; ++i) {
    //текстовые узлы и комментарии
    if(bodyChildren[i].nodeType == 3 || bodyChildren[i].nodeType == 8) {
        bodyChildren[i].data = "$"
       }
  }
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.