How can I tell when the width of an inner element exceed that of the outer element

I need to find a way of finding out whether the inner child element’s width exceeds that of the parent element. The following is my code.

<section class="anchor-links">
    <div class="container">
        <div class="wrapper">
            <div class="content">
                <img decoding="async" class="left-arrow" src="https://staging.slattery.co.uk/wp-content/uploads/2024/06/burgundy.svg">
                <div class="anchor-row">
                                        <div class="anchor-link">
                        <a href="#breakfast-and-sandwiches"><h3>Breakfast & Sandwiches</h3></a>
                    </div>
                                        <div class="anchor-link">
                        <a href="#on-toast"><h3>On Toast</h3></a>
                    </div>
                                        <div class="anchor-link">
                        <a href="#egg-dishes"><h3>Egg</h3></a>
                    </div>
                                        <div class="anchor-link">
                        <a href="#morning-goods"><h3>Morning Goods</h3></a>
                    </div>
                                        <div class="anchor-link">
                        <a href="#extras"><h3>Extras</h3></a>
                    </div>
                                        <div class="anchor-link">
                        <a href="#sweet-choices"><h3>Sweet Choices</h3></a>
                    </div>
                                    </div>
                <img decoding="async" class="right-arrow" src="https://staging.slattery.co.uk/wp-content/uploads/2024/06/burgundy.svg">
            </div>
        </div>
    </div>
</section>

Essentially, the arrow images should only show to indicate when there are more options to show (when there is an overflow). Take a look at the images below. Image 1 requires no arrows because the menu does not overflow whereas image 2 will need the arrows as the image overflows.

image 1 – no arrows needed
image 2 – arrows needed

Thank you in advance

I tried the following code

if(document.querySelector('.page-id-1065') || document.querySelector('.page-id-1801')) {
    console.log('Correct page')
    const parentElement = document.querySelector('.anchor-links .content');
    const listElement = document.querySelector('.anchor-links .content .anchor-row');

    // Check if the list exceeds the parent element's width
    if (listElement.scrollWidth > parentElement.scrollWidth) {
        console.log('The list exceeds the width of its parent!');
    } else {
        console.log('The list fits within the parent element.');
    }
}

It gave the else outcome both times.

2

const windowHeight = window.innerHeight;
const browserHeight = document.documentElement.clientHeight;

console.log("Pencere Yüksekliği:", windowHeight);
console.log("Tarayıcı Yüksekliği:", browserHeight);

// İç öğenin genişliğinin ana öğeyi aşıp aşmadığını kontrol etme
function checkOverflow(innerElement, outerElement) {
    const innerWidth = innerElement.scrollWidth; // İç öğenin tam genişliği
    const outerWidth = outerElement.clientWidth; // Ana öğenin görünür genişliği

    if (innerWidth > outerWidth) {
        console.log("İç öğe, ana öğeyi aşıyor.");
    } else {
        console.log("İç öğe, ana öğeye sığıyor.");
    }
}

// Örnek kullanım:
const innerElement = document.querySelector('.inner-child'); // İç öğe
const outerElement = document.querySelector('.outer-parent'); // Ana öğe

checkOverflow(innerElement, outerElement);

enter code here

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật