Skip to content

Instantly share code, notes, and snippets.

@rbk
Created July 27, 2017 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbk/c7162fd43d74a1a94ae3691743d9b642 to your computer and use it in GitHub Desktop.
Save rbk/c7162fd43d74a1a94ae3691743d9b642 to your computer and use it in GitHub Desktop.
Find out if any elements are wider that the screen size.
function findElementsLargerThanScreen() {
var elements = document.querySelectorAll('*')
for (var i = 0; i < elements.length; i++) {
var elementWidthInt = 0;
var elementWidth = window.getComputedStyle(elements[i], null).width
if (elementWidth !== 'auto') {
elementWidthInt = parseFloat(elementWidth.replace('px', ''));
if (elementWidthInt > screen.width) {
console.log(elementWidthInt)
} else {
console.log('no')
}
}
}
}
findElementsLargerThanScreen()
document.addEventListener('click', findElementsLargerThanScreen)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment