Get elements bigger than viewport

JavaScript, Browser · Oct 22, 2020

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

const getElementsBiggerThanViewport = () => {
  const docWidth = document.documentElement.offsetWidth;
  return [...document.querySelectorAll('*')].filter(
    el => el.offsetWidth > docWidth
getElementsBiggerThanViewport(); // <div id="ultra-wide-item" />

More like this

  • Array of element's siblings

    JavaScript, Browser

    Returns an array containing all the siblings of the given element.

  • Array to HTML list

    JavaScript, Browser

    Converts the given array elements into <li> tags and appends them to the list of the given id.

  • Get all images in element

    JavaScript, Browser

    Fetches all images from within an element and puts them into an array.