Skip to content

Instantly share code, notes, and snippets.

@panphora
Created July 26, 2019 18:55
Show Gist options
  • Select an option

  • Save panphora/44ce3a407caffe0a347c4cbb3b7e5849 to your computer and use it in GitHub Desktop.

Select an option

Save panphora/44ce3a407caffe0a347c4cbb3b7e5849 to your computer and use it in GitHub Desktop.
var elem = document.querySelector("body");
function deepForEachElem (elem, callback) {
callback(elem);
Array.from(elem.children || []).forEach(function (el) {
deepForEachElem(el, callback);
});
}
deepForEachElem(elem, function (el) {
let width = el.getBoundingClientRect().width;
console.log(width, el);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment