Lwis wrote:
Hi,

short version: how do I find out whether my element is a child of
another element?

long version: I think I want to loop through all elements and check
each of them if it is the element I am searching for or not.

I think I want something similar to YUI (http://www.un-instraw.org/
wiki/training/skins/ycal/yui/docs/treeview/overview-summary-
Node.js.html)
isChildOf function.

Any ideas would be appreciated.
Thanks


function isChildOf (parentEl, el, container) {
           if (parentEl == el) {
               return true;
           }
           if (parentEl.contains && !$.browser.safari) {
               return parentEl.contains(el);
           }
           if ( parentEl.compareDocumentPosition ) {
               return !!(parentEl.compareDocumentPosition(el) & 16);
           }
           var prEl = el.parentNode;
           while(prEl && prEl != container) {
               if (prEl == parentEl)
                   return true;
               prEl = prEl.parentNode;
           }
           return false;
       }


parentEl = possible parent
el = the subject
container = stop search the this element

Reply via email to