[Greasemonkey] Basic JavaScript questions

chris feldmann cfeldmann at gmail.com
Wed Jun 29 17:04:12 EDT 2005


1. e.nodeValue
2. is it maybe getting shorter because you're removing a node on each 
iteration?

And when you say it's doing nothing, you mean other than logging, right? 
What exactly is getting logged?


On 6/29/05, The Chris Method <thechrisproject at gmail.com> wrote:
> 
> I'm trying to write a basic script, one that removes all <h3> tags from a 
> certain webpage (overheardinnewyork.com <http://overheardinnewyork.com>). 
> I have some pretty basic JavaScript<http://en.wikipedia.org/wiki/JavaScript>questions:
> 
> 1) In debugging my code, I've been trying to figure out a way to access 
> the info inside the tags, i.e. the "text" in <h3>text</h3>. If 'e' is a 
> node representing this element, how do I get the text inside? e.firstChildgives me [object Text] and 
> e.firstChild.value gives me 'undefined'.
> 
> 2) My first guess on how to actually accomplish the aforementioned task 
> was this:
> 
> (function() {
> var e, i, all;
> 
> all = document.getElementsByTagName("h3");
> for (i = 0; i < all.length; i += 1) {
> e = all[i];
> GM_log('removing node ' + e.firstChild + ' all.length: ' + all.length);
> e.parentNode.removeChild(e);
> }
> })();
> 
> 
> This does nothing. 'all', which is supposed to be a read-only array 
> (according to my JS ref book), gets one item shorter every time I iterate 
> through the for loop, and i increments. So then I change the condition on 
> the loop from i<all.length to all.length>0. This removes them all. But it 
> seems ugly to me. I guess I'm looking for code critiques and ideas for 
> better ways to do this. Could this all be done with some sort of css fun? 
> 
> If my approach is to just remove the h3 elements entirely, what is the 
> best way? 
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
> 
> 
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mozdev.org/pipermail/greasemonkey/attachments/20050629/c6964ecc/attachment.htm


More information about the Greasemonkey mailing list