I have nested carousels and i need to select only the buttons from each carousel ( and not the ones in nested carousels )
So I need the reverse that .closest
does..
This is how I'm trying
const container = document.querySelector('#selector');
document.querySelector('span').innerHTML = container.querySelectorAll(':not(.carrousel-container) .carousel_container__button').length
<div class="carrousel-container" id="selector">
<button class="carousel_container__button">The only one i want</button>
<div class="carrousel-container">
<button class="carousel_container__button">other carousel button</button>
</div>
<div class="carrousel-container">
<button class="carousel_container__button">other carousel button</button>
</div>
</div>
<p>Found items: <span></span></p>
But I always get 3 and i need to select just the first one.
Why is the :not()
not enough?
Note that I can't use > button
because the content is very different in each