Apologies if this is daft but I'm going a bit mad with this issue i think. I keep getting an undefined error when logging my querySelectorAll to the console. I would like to add a click event on the querySelectorAll selector below eventually once i can work out the issue. All i want is the btn click handler to work when the section has class active.
<section class="section test active">
<div class="btn"></div>
</section>
<section class="section test">
<div class="btn"></div>
</section>
var btn = document.querySelectorAll('.section.active .btn');
console.log(btn[0]);
This shows undefined.
What i am looking to do is something like
var btn = document.querySelectorAll('.section.active .btn');
btn.addEventListener('click', function() {
//Do something
});
EDIT Sorry i forgot to add the class section to the section tag
Appreciate any advice