Posted By

noah on 07/20/07


DOM tree hierarchy traversal utilities parentNode

Versions (?)

find ancestor

 / Published in: JavaScript

find the first ancestor on which comparisonFunc evaluates to true works the same way as a custom sort the el specified in the pram will be the FIRST el to which comparisonFunc is applied.

this is, this function considers me to be my own first ancestor :)

  1. /****************************************************************
  2.   ** Find Ancestor for which a function returns true
  3.   ****************************************************************/
  4. findAncestor: function ( el, comparisonFunc ) {
  5. if (comparisonFunc(el) == true) return el;
  6. else if (el.parentNode) {
  7. return arguments.callee(el.parentNode, comparisonFunc);
  8. }
  9. else return false;
  10. }

Report this snippet  

You need to login to post a comment.