Detect Overflows in JavaScript

PHOTO EMBED

Thu Jan 26 2023 08:26:55 GMT+0000 (Coordinated Universal Time)

Saved by @gnomiesaurus #javascript

const findOverflows = () => {
    const documentWidth = document.documentElement.offsetWidth;

    document.querySelectorAll('*').forEach(element => {
        const box = element.getBoundingClientRect();

        if (box.left < 0 || box.right > documentWidth) {
            console.log(element);
            element.style.border = '1px solid red';
        }
    });
};

// Execute findOverflows to find overflows on the page.
findOverflows();
content_copyCOPY

https://www.webtips.dev/webtips/javascript/find-overflowing-elements-with-javascript