Kalvin
2007-Jun-28 19:30 UTC
img element inside div not accessible with $$() or getElementsBySelector
I can''t access an img inside a div using the $$() syntax. Using getElementsBySelector doesn''t work either. Both return empty arrays. I can access it with getElementById, however. <div id="foo"> <img id="image" src="blah.jpg"> <div id="bar" </div> - Using $$(''#foo img'') returns an empty array - Using $(''foo'').getElementsBySelector(''img'') gets me an empty array - Using $(''foo'').childElements() gets me an array with ''blah'' inside... but not the img. - Using $(''image'') works. To me, it looks like img doesn''t count as an element of any kind. But I don''t see how that''s possible, and from the docs it doesn''t look like it''s supposed to work that way. Is this a bug or am I missing something? Thanks for your help! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Diodeus
2007-Jun-28 19:42 UTC
Re: img element inside div not accessible with $$() or getElementsBySelector
This successfully alerted the image source name: <div id="foo"> <img id="image" src="blah.jpg"> <div id="bar" </div> <script language=javascript> var thing = $$(''#foo img'') alert(thing[0].src) </script> If it doesn''t work for you maybe you should grab a fresh copy of Prototype. On Jun 28, 3:30 pm, Kalvin <findkal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I can''t access an img inside a div using the $$() syntax. Using > getElementsBySelector doesn''t work either. Both return empty arrays. I > can access it with getElementById, however. > > <div id="foo"> > <img id="image" src="blah.jpg"> > <div id="bar" > </div> > > - Using $$(''#foo img'') returns an empty array > - Using $(''foo'').getElementsBySelector(''img'') gets me an empty array > - Using $(''foo'').childElements() gets me an array with ''blah'' > inside... but not the img. > - Using $(''image'') works. > > To me, it looks like img doesn''t count as an element of any kind. But > I don''t see how that''s possible, and from the docs it doesn''t look > like it''s supposed to work that way. Is this a bug or am I missing > something? > > Thanks for your help!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Kalvin
2007-Jun-29 17:23 UTC
Re: img element inside div not accessible with $$() or getElementsBySelector
Oh, shoot-- you''re right, it does work. The issue I''m actually having is that $$(''img:not(#bag img)'') returns all imgs including #bag img... but I don''t think using two selectors is actually supported. (Someone tell me if I''m wrong!) Thanks for your help! On Jun 28, 12:42 pm, Diodeus <diod...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This successfully alerted the image source name: > > <div id="foo"> > <img id="image" src="blah.jpg"> > <div id="bar" > </div> > <script language=javascript> > var thing = $$(''#foo img'') > alert(thing[0].src) > </script> > > If it doesn''t work for you maybe you should grab a fresh copy of > Prototype. > > On Jun 28, 3:30 pm, Kalvin <findkal...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I can''t access an img inside a div using the $$() syntax. Using > > getElementsBySelector doesn''t work either. Both return empty arrays. I > > can access it with getElementById, however. > > > <div id="foo"> > > <img id="image" src="blah.jpg"> > > <div id="bar" > > </div> > > > - Using $$(''#foo img'') returns an empty array > > - Using $(''foo'').getElementsBySelector(''img'') gets me an empty array > > - Using $(''foo'').childElements() gets me an array with ''blah'' > > inside... but not the img. > > - Using $(''image'') works. > > > To me, it looks like img doesn''t count as an element of any kind. But > > I don''t see how that''s possible, and from the docs it doesn''t look > > like it''s supposed to work that way. Is this a bug or am I missing > > something? > > > Thanks for your help!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Apparently Analagous Threads
- getElementsBySelector problem in IE
- bug: Element.getElementsBySelector on internet explorer
- getElementsBySelector broken in IE
- Using Prototype - Getting Javascript Error - "Object doesn't support this property or method"
- Quick Element.getElementsBySelector() question