We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

noah on 07/20/07


Tagged

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.