Get elements bigger than viewport
Returns an array of HTML elements whose width is larger than that of the viewport's.
- Use
HTMLElement.offsetWidth
to get the width of theDocument
. - Use
Array.prototype.filter()
on the result ofDocument.querySelectorAll()
to check the width of all elements in the document.
const getElementsBiggerThanViewport = () => { const docWidth = document.documentElement.offsetWidth; return [...document.querySelectorAll('*')].filter( el => el.offsetWidth > docWidth ); }; getElementsBiggerThanViewport(); // <div id="ultra-wide-item" />