I just realized that my function had different behaviour for strings.
I found a simpler way of doing it, a bit slower, and it doesn't use
the cointains/compareDocumentPosition optimization for single
elements. Also it should be 'descendantOf' or something.

Currently :has is implemented using find().length. contains /
compareDocumentPosition could be implemented in jQuery.has and :has
built on top of it. That way it's functionality would be exposed and
we could do the same in the opposite way:

$(a).has(b)
$(document).has(a);

any thoughts?

On Jan 23, 3:59 pm, Ricardo Tomasi <[email protected]> wrote:
> 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