ricardo,

On 30 Nov, 19:35, ricardobeat <[EMAIL PROTECTED]> wrote:
> Hi,
>
> It seems the ownerDocument is set for the created element even if it's
> not in the DOM, it's the document where jQuery was loaded in. A simple

Correct, the "ownerDocument" will always be available, but it will
reference the "document" you used to create the element
(document.createElement), which may be a different one than the one
jQuery was loaded in.

> check for parentNode or offsetParent would do:
>
> $.fn.inDOM = function(){
>      return !!this.parentNode; //boolean
>
> });
>

It is not enough to check the first parent node, you will have to
traverse up until the last parent is found, if the last parent is not
"nodeType == 9" (a document node) it means the element is detached
from a DOM tree.

> parentNode returns faster for elements in the DOM, while offsetParent
> returns faster for elements not in the DOM (in FF3 at least).

I believe that native compareDocumentPosition/contains are much
faster.

--
Diego

>
> Hope I'm not missing anything. It surely would need a better name :]
>
> cheers,
> - ricardo
> On 29 nov, 14:46, Ariel Flesler <[EMAIL PROTECTED]> wrote:
>
> > 'body' should be replaced by 'html'.
>
> > Maybe we can make it faster by consulting expandos like
> > ownerDocument ?
>
> > --
> > Ariel Fleslerhttp://flesler.blogspot.com
>
> > On Nov 27, 12:52 am, diogobaeder <[EMAIL PROTECTED]> wrote:
>
> > > Hi there,
>
> > > I'm new here (and in jQuery), but even though I'd like to propose some
> > > simple but usefull method to the jQuery object (at core.js) to tell
> > > the API user if an element exists in the document. I've tried to build
> > > one as follows:
>
> > > [CODE]
> > > (function($) {
>
> > >     $.fn.inDOM = function() {
> > >         return !!this.parents('body').length;
> > >     };
>
> > > })(jQuery);
>
> > > jQuery(document).ready(function(){
> > >     var jEl = $('.someExistingClass');
>
> > >     // Should be in DOM
> > >     console.debug(jEl.inDOM());
>
> > >     // Removing the element
> > >     jEl.remove();
>
> > >     // Should NOT be in DOM
> > >     console.debug(jEl.inDOM());});
>
> > > [/CODE]
>
> > > So, if the client sets a variable as a jQuery object, and at some
> > > point of the code the DOM element within it can be removed, he/she can
> > > test if it really was. OK, I know it sounds unsignificant, but I think
> > > it would still be usefull.
>
> > > Thanks!
>
> > > Diogo Baeder
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to