One ! instead of two !!. If the element is found in the document, then it * isn't* orphaned.
And yes you need to check for the body in the parent chain because the element might be part of a whole tree that's been orphaned. It still has a parent (element.up() != null) but the parent has been orphaned as well. There's always the recursive approach, which will be nice when JS supports tail recursion: ;-) function isOrphaned(element) { return !element.parentNode || isOrphaned(element.parentNode); } -Fred On Mon, Jun 30, 2008 at 1:22 PM, kangax <[EMAIL PROTECTED]> wrote: > > I believe this could be shortened like so: > > Element.addMethods({ > isOrphaned: function(element){ > if (element.id) { > return !!element.ownerDocument.getElementById(element.id); > } > return !!element.up('body'); > } > }); -- Science answers questions; philosophy questions answers. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---