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.

#sidebar a { color:#fff; } #sidebar ul ul li { color: #DEF585; } #sidebar h2 { color: #fff; } #sidebar ul p, #sidebar ul select { color: #BEDDBE; } #backfly { background: url(images/golfBallWallPaper.jpg) left bottom fixed repeat-x #65a51d; }