Hello, I was wondering whether somebody can give me a little hand on this: I have the following code: "var img = this.el.previousSibling.getElementsByTagName(''IMG'')[0];" While IE correctly returns the image object, Firefox returns an error. What I discovered so far is that this.el.previousSibling returns the DIV tag an IE which is correct - however, Firefox returns this: #text. I was wondering whether there is some use of the prototype cleanWhitespace but I couldn''t make this to work yet. Does anybody see a workaround/. Thank you in advance for your help. _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today - it''s FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
sanzbox-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
2005-Nov-07 08:25 UTC
Re: IE vs. Firefox - little programming help needed
1st, if you don''t already have it running, install firefox with the Javascript debugger (need to use the ''custom install'' feature). You''ll then be able to see exactly how the dom tree is layed out on each page (text + div + other elements, etc)>From what you''ve written it looks like you''re gettinga text element instead of the div you desire. That''s probably the correct behavior, since any text will generate a text element. So instead of trying to use some sort of relative/proximity access scheme, I''d suggest an alternate more explicit approach. Perhaps naming your ''divs'' with a numbering scheme if you''re generating them dynamically (e.g. ''item_21'', ''item_22'', etc.) as well as your images (<img id=''img_21'' ...) Then you can just parse off the number (indexOf + substr) and lookup the associated ''item''/div explicitly with getElementById(''item_'' + idnumber). Not sure if that will fit your situation. Cheers, -San --- "Marco M. Jaeger" <mmjaeger-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> > Hello, > > I was wondering whether somebody can give me a > little hand on this: > > I have the following code: "var img = >this.el.previousSibling.getElementsByTagName(''IMG'')[0];"> > While IE correctly returns the image object, Firefox > returns an error. What > I discovered so far is that this.el.previousSibling > returns the DIV tag an > IE which is correct - however, Firefox returns this: > #text. > > I was wondering whether there is some use of the > prototype cleanWhitespace > but I couldn''t make this to work yet. > > Does anybody see a workaround/. > > Thank you in advance for your help. > >_________________________________________________________________> Express yourself instantly with MSN Messenger! > Download today - it''s FREE! >http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/> > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs>__________________________________ Yahoo! Mail - PC Magazine Editors'' Choice 2005 http://mail.yahoo.com
You could do something like this: var prev = this.el.previousSibling; while (prev.tagName != ''DIV'') { prev = prev.previousSibling; } var img = prev.getElementsByTagName(''IMG'')[0]; It''s a bit hackish, but it should work. Firefox seems to insert random extra elements in the DOM like that. I had the same problem with a <TR> having childNodes that were text nodes (although the only elements on the page were <TD> elements). I''m not quite sure where they came from, but I just removed all the non <TD> childNodes from the DOM altogether. Everything rendered the same, and the code behaved as desired. Greg -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Marco M. Jaeger Sent: Monday, November 07, 2005 12:54 AM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] IE vs. Firefox - little programming help needed Hello, I was wondering whether somebody can give me a little hand on this: I have the following code: "var img = this.el.previousSibling.getElementsByTagName(''IMG'')[0];" While IE correctly returns the image object, Firefox returns an error. What I discovered so far is that this.el.previousSibling returns the DIV tag an IE which is correct - however, Firefox returns this: #text. I was wondering whether there is some use of the prototype cleanWhitespace but I couldn''t make this to work yet. Does anybody see a workaround/. Thank you in advance for your help. _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today - it''s FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs