{"id":787,"date":"2015-03-24T02:43:17","date_gmt":"2015-03-24T02:43:17","guid":{"rendered":"http:\/\/blog.silverterra.net\/?p=787"},"modified":"2015-03-24T02:43:17","modified_gmt":"2015-03-24T02:43:17","slug":"get-all-the-parents","status":"publish","type":"post","link":"https:\/\/blog.silverterra.net\/?p=787","title":{"rendered":"get all the parents"},"content":{"rendered":"<blockquote><p>Goal: create a simple way to collect all the parents<\/p><\/blockquote>\n<p>The code is the simpliest on the world:<\/p>\n<pre data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">\r\nfunction getParents(el){\r\n  var ret = [], getP = function(el){ return el.parentNode; };\r\n  while(el){ el = getP(el), el &amp;&amp; ret.push(el); }  \r\n  return ret;  \r\n};\r\n<\/pre>\n<p>&#8230;the result is an array with the parents of the element.<br \/>\nThe same idea but width size:<\/p>\n<pre data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">\r\nfunction getParentsW(el){\r\n  var ret = [], getP = function(el){ return el.parentNode; };\r\n  while(el){ el = getP(el), el &amp;&amp; ret.push(el.offsetWidth); }  \r\n  return ret;  \r\n};\r\n<\/pre>\n<p>&#8230;the result is an array with the width of all the parents of the element.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Goal: create a simple way to collect all the parents The code is the simpliest on the world: &#8230;the result is an array with the parents of the element. The same idea but width size: &#8230;the result is an array with the width of all the parents of the element.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-787","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=787"}],"version-history":[{"count":1,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/787\/revisions"}],"predecessor-version":[{"id":788,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/787\/revisions\/788"}],"wp:attachment":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}