i have a sample calculator html template
<div id="container">
<div id="display" class="t4"></div>
<div id="buttons">
<div class="t1">7</div>
<div class="t1">8</div>
<div class="t1">9</div>
<div class="t1">/</div>
<div class="t1">4</div>
<div class="t1">5</div>
<div class="t1">6</div>
<div class="t1">*</div>
<div class="t1">1</div>
<div class="t1">2</div>
<div class="t1">3</div>
<div class="t1">-</div>
<div class="t1">0</div>
<div class="t1">.</div>
<div class="t1">+</div>
<div id="calculate"class="t1">=</div>
</div>
where I want to add an event listener and get the value to be the operation/number to be executed,
but whenever I try to get the div's in a variable in my javascript file, it just turns out to be null
const keys = document.querySelector('buttons');
console.log(keys)
i have also tried with the document.getElementById
function
with no luck.. is it because I'm not inside a function or is it because I',m assigning it to a value?
when I do it inside a function
function myFunction() {
const buttons =document.getElementById('buttons')
console.log(buttons)
}
it works fine?