By javascript? ..
The comment can be located in any part of the html-document both in the hid and in the body, is at the beginning of the line.

  • well, but the algorithm of iteration over all elements of the DOM to search for comments is also of interest, BUT! without frameworks, you need a clean javascript - deivan_
  • Since the accepted answer contains this algorithm and at least jQuery, just have to walk not through the divs, but throughout the document - Specter
  • This algorithm is good for climbing inside the container, but not at all across the DOM. The weakness of the algorithm is in the absence of processing nesting levels. - deivan_

1 answer 1

And again I answer myself:

var allComments = []; // массив результатов getElems(document); console.log(allComments); function getElems(el) { // рекурсивная функция, // которая обходит все уровни вложенности ДОМ var chNodes, i; if (el.nodeType == 8) { // это код ноды-комментария allComments.push(el.nodeValue); // прячем в массив сам комментарий, // можно сделать еще что-то } if (el.hasChildNodes()) { chNodes = el.childNodes; for (i = 0; i < chNodes.length; i++) { getElems(chNodes[i]); } } } 

Thank you all for your attention.

  • one
    you can close the question. - deivan_