I implemented that in a plugin:

jQuery.fn.childOf = function(c){
    if (c.jquery) c = c[0];
    if (c.indexOf) return !!jQuery.filter(c,this.parents().get
()).length;
    var el = this[0];
    return (!el || !c) ? false
                : (c.contains)
                        ? c.contains(el)
                        : !!(c.compareDocumentPosition(el) & 16);
};

You can pass in either an HTMLElement, a jQuery object or a selector
string. But it only checks the first element in the jQuery object,
doing it for every element (or every possible parent in the passed
object) takes a lot more code, and I'm not sure about the approach.

Any plans of something like this being added to the core? It would
also cover the "inDOM" function proposed by Diogo Baeder a while ago -
$(element).childOf(document);

cheers,
- ricardo

On Jan 22, 11:45 pm, Dave Methvin <[email protected]> wrote:
> The original question was whether it was a child, which is a bit
> simpler:
>
> $(a.childNodes).index(b) >= 0
>
> The quickest way to determine the descendant case would be with IE's
> contains method or the W3c compareDocumentPosition method.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to [email protected]
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