Returns an array of HTML elements whose width is larger than that of the viewport's.
HTMLElement.offsetWidth
to get the width of the Document
.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, Browser
Returns an array containing all the siblings of the given element.
JavaScript, Browser
Converts the given array elements into <li>
tags and appends them to the list of the given id.
JavaScript, Browser
Fetches all images from within an element and puts them into an array.