Hey guys I have a bunch of element fragments (ie this might be a div, with children of an image, another div) etc which aren''t attached to the document yet.. and can''t seem to call the dom manipulation methods on them: down(''img.icon'') returns undefined but if I look at the innerHTML of the element, there is clearly an image there with that class. Is this is a known limitation and what options do I have? Everything is encapsulated in functions, so I know I need an image tag there, but I dont know the source until the callee performs some further ifs, however I need the element for this ifs, it''s sorta a catch 22.. so I generate the dom fragment and then want to set the image src later- except I cant get a reference until its attached... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
How do create this snippet of code? Cause if you just inserted a string in the div with innerHTML, I can understand why it isn''t working. It''s better if you just create the elements bfore you insert them into the div. var container = new Element(''div''); var image = new Element(''img''); container.insert(image); that way you already have a refrence to the element you need to call. img.writeAttribute(''src'', ''path/image.gif''); Greetz, Wizz On 21 dec, 04:51, "Gareth Evans" <agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey guys > > I have a bunch of element fragments (ie this might be a div, with children > of an image, another div) etc which aren''t attached to the document yet.. > and can''t seem to call the dom manipulation methods on them: > > down(''img.icon'') returns undefined but if I look at the innerHTML of the > element, there is clearly an image there with that class. > > Is this is a known limitation and what options do I have? > > Everything is encapsulated in functions, so I know I need an image tag > there, but I dont know the source until the callee performs some further > ifs, however I need the element for this ifs, it''s sorta a catch 22.. so I > generate the dom fragment and then want to set the image src later- except I > cant get a reference until its attached...--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Wizz, yeah I create the elements with new Element but it''s inside a function; so i call the function which builds the dom snipped (it''s passed some stuff it needs) I guess I could make it return an object with more than one dom object so I have access to the image as it already returns the final snippet I was just wondering if the nav methods were meant to work on detached nodes. Gareth On 12/22/07, Wizz <woutawizz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > How do create this snippet of code? Cause if you just inserted a > string in the div with innerHTML, I can understand why it isn''t > working. > > It''s better if you just create the elements bfore you insert them into > the div. > > var container = new Element(''div''); > var image = new Element(''img''); > container.insert(image); > > that way you already have a refrence to the element you need to call. > > img.writeAttribute(''src'', ''path/image.gif''); > > Greetz, > > Wizz > > On 21 dec, 04:51, "Gareth Evans" <agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hey guys > > > > I have a bunch of element fragments (ie this might be a div, with > children > > of an image, another div) etc which aren''t attached to the document > yet.. > > and can''t seem to call the dom manipulation methods on them: > > > > down(''img.icon'') returns undefined but if I look at the innerHTML of the > > element, there is clearly an image there with that class. > > > > Is this is a known limitation and what options do I have? > > > > Everything is encapsulated in functions, so I know I need an image tag > > there, but I dont know the source until the callee performs some further > > ifs, however I need the element for this ifs, it''s sorta a catch 22.. so > I > > generate the dom fragment and then want to set the image src later- > except I > > cant get a reference until its attached... > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Gareth, DOM traversal methods which are forced to use XPATH ( i.e. when you pass selector string rather than numbered value ) on uninserted nodes actually fail due to a bug. The fix http://dev.rubyonrails.org/ticket/10508 will most likely make its way into 1.6.1, so no worries : ) Best, kangax --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
hmm... Last commit http://dev.rubyonrails.org/changeset/8448 actually fixed .down issue as it now uses .select instead of .findElements, but up/prev/next still suffer from this... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Awesome, glad I wasn''t just cracking up. It took me a while to figure out I only got undefined coming back when it was unattached, but I hadn''t traced it through the internal code. Seems there''s no need now. Here''s hoping savetheclocktower fixes it for all 4 methods- it''s definitely useful if you want to wrap things up in small functions like I do, meaning you dont have direct access to the child dom elements. I''ve patched my code for now to just use childNodes[1].childNodes[0] to get to where i want- i dont know if down(2) will work. Gareth On Dec 22, 2007 9:59 PM, kangax <kangax-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > hmm... > > Last commit http://dev.rubyonrails.org/changeset/8448 actually > fixed .down issue as it now uses .select instead of .findElements, but > up/prev/next still suffer from this... > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---