get all the parents [ 907 views ]
Goal: create a simple way to collect all the parents
The code is the simpliest on the world:
function getParents(el){ var ret = [], getP = function(el){ return el.parentNode; }; while(el){ el = getP(el), el && ret.push(el); } return ret; };
…the result is an array with the parents of the element.
The same idea but width size:
function getParentsW(el){ var ret = [], getP = function(el){ return el.parentNode; }; while(el){ el = getP(el), el && ret.push(el.offsetWidth); } return ret; };
…the result is an array with the width of all the parents of the element.