I am trying to write an "ancestor function". it will take three values child parent and stop. All three are elements. The purpose is to check whether child is located under parent in the DOM. It should only search until it reachs stop(or the parent).It will then return true or false accordingly. I hope that makes sense. Here's my attempt.
Unfortunately, I can't get it working. The firefox error console says "child has no properties"(references bolded line). Any help is appreciated as I really need this function to work(I can't think of any other way)Code:function ancestor(child,parent,stop){ if(child.parentNode){ while(child != stop){ if(child.parentNode == parent){ return true; } else{ child = child.parentNode; } } } return false; }



Reply With Quote


Bookmarks