Skip to content

Instantly share code, notes, and snippets.

@heyMP
Created September 9, 2021 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heyMP/1092481aa9197269599a300946a1c06a to your computer and use it in GitHub Desktop.
Save heyMP/1092481aa9197269599a300946a1c06a to your computer and use it in GitHub Desktop.
Find comments inside of a DOM element
const findComments = function (el) {
var arr = [];
for (var i = 0; i < el.childNodes.length; i++) {
var node = el.childNodes[i];
if (node.nodeType === 8) {
arr.push(node);
} else {
arr.push.apply(arr, findComments(node));
}
}
return arr;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment