Skip to content

Instantly share code, notes, and snippets.

@yuest
Created March 1, 2012 11:12
Show Gist options
  • Save yuest/1949131 to your computer and use it in GitHub Desktop.
Save yuest/1949131 to your computer and use it in GitHub Desktop.
获取文档中所有注释节点
document.getComments = function getComments(pnode, result) {
pnode = pnode || document.documentElement
result = result || []
var cnodes = pnode.childNodes
, cnode, i
for (i = -1; (cnode = cnodes[++i]); ) {
if (cnode.nodeType !== 8) {
getComments(cnode, result)
} else {
result.push(cnode)
}
}
return result
}
@tualatrix
Copy link

Hello world

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment