771 B
771 B
title, tags, expertise, cover, firstSeen, lastUpdated
| title | tags | expertise | cover | firstSeen | lastUpdated |
|---|---|---|---|---|---|
| Get elements bigger than viewport | browser | intermediate | blog_images/case-study.jpg | 2020-10-06T17:41:22+03:00 | 2020-10-22T20:23:47+03:00 |
Returns an array of HTML elements whose width is larger than that of the viewport's.
- Use
HTMLElement.offsetWidthto 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" />