here's my take on 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;
};
Tested in Firefox 2.0. & Opera. Along the way I found that in FF comments in
a <noscript> are not broken out in the dom. A minor inconvenience!
and in Safari comments from the original page are not include in the dom. A
major inconvenience!
Oh well!
--
Ⓙⓐⓚⓔ - יעקב ʝǡǩȩ ᎫᎪᏦᎬ
On 11/27/06, Paul McLanahan <[EMAIL PROTECTED]> wrote:
Could be a cool addition to the metadata plugin. It's more semantic in
my opinion to have the meta data in a script tag if you don't wan it
directly attached to a dom element, but it would be cool nonetheless.
On 11/27/06, Ⓙⓐⓚⓔ <[EMAIL PROTECTED]> wrote:
> Although we rarely want to pay any attention (programmatically) to the
> comments in the html, I thought it would be cool to read them in jquery.
>
> They are in the dom, obj.nodeType == COMMENT_NODE. But jquery just skips
> over that node type.
>
> I could imagine doing $('a').prevComments() or $('a').nextComments() or
> $('a').Comments()
>
> A plugin could drop down to simple dom navigation to get the info and
then
> return the text.
>
> Has anyone done this? Does it sound useful to anyone?
>
> --
> Ⓙⓐⓚⓔ - יעקב ʝǡǩȩ ᎫᎪᏦᎬ
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
>
>
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/