Created
April 13, 2011 20:30
-
-
Save dbergey/918337 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from: http://forum.jquery.com/topic/jquery-reading-comments-from-the-dom | |
jQuery.fn.comments = function(location) { | |
var location = location || "inside"; | |
var comments = []; | |
this.each(function() { | |
if (location == "inside") { | |
var children = this.childNodes | |
for (var i = 0; i < children.length; i++) { | |
var child = children[i]; | |
if (child.nodeType == 8) comments[comments.length] = $.trim(child.nodeValue); | |
} | |
} else if (location=="after") { | |
for (var next = this.nextSibling;next;next = next.nextSibling) | |
if (next.nodeType == 8) comments[comments.length] = $.trim(next.nodeValue); | |
} else if (location=="before") { | |
for (var prev = this.previousSibling; prev; prev = prev.previousSibling) | |
if (prev.nodeType == 8) comments[comments.length] = $.trim(prev.nodeValue); | |
} | |
}); | |
return comments; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment