function checkBanner() {
var banner = document.querySelector('.banner-section');
if (!banner.length) {
document.querySelector('body').classList.add('no-banner')
}
}
checkBanner();
<body>
<div class="banner-section">
<div class="banner">
<h1>Lorem ipsum dolor sit amet.</h1>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Corporis, harum?</p>
</div>
</div>
</body>
The JavaScript code I wrote isn't functioning correctly. It's currently only adding a no-banner class to the body tag, but my intention is for a class to be added to the body tag if the banner-section class is empty.