Skip to content

Instantly share code, notes, and snippets.

@karlcow
Created September 2, 2019 04:41
Show Gist options
  • Save karlcow/ef42b4617e2cc4a15d62b62d47fe7112 to your computer and use it in GitHub Desktop.
Save karlcow/ef42b4617e2cc4a15d62b62d47fe7112 to your computer and use it in GitHub Desktop.
Iterate through the DOM to search element wider than a certain width.
// Iterate through the DOM to search element wider than a certain width.
// Practical for issues with invisible blocks creating layout issues
// on mobile.
// set here the maxwidth of your choice.
var maxwidth = 414;
var startElem = document.getElementsByTagName('body')[0];
var items = startElem.getElementsByTagName("*");
for (var i = items.length; i--;) {
if (items[i].getBoundingClientRect()['width'] > maxwidth) {
console.log(items[i], items[i].getBoundingClientRect()['width'])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment