Menu

gitpiper

getElementsBiggerThanViewport javascript Code Snippet in 2024

browserintermediate

Last Updated: 21 April 2024

Returns an array of HTML elements whose width is larger than that of the viewport's.

  • Use HTMLElement.offsetWidth to get the width of the document.
  • Use Array.prototype.filter() on the result of Document.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" />

javascript snippet similar to getElementsBiggerThanViewport For You in April 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️