Lets say I had a group of buttons in this structure, that I wanted to access through JavaScript
<div id="container">
<button id="one">One</button>
<button id="two">Two</button>
<button id="three">Three</button>
<button id="four">Four</button>
<button id="five">Five</button>
<button id="six">Six</button>
<button id="seven">Seve</button>
<button id="eight">Eight</button>
<button id="nine">Nine</button>
<button id="ten">Ten</button>
</div>
Efficiency-wise, would it be better to:
A) Use document.getElementById
for it to scan the DOM each time, and get the buttons
B) Use document.getElementById
to get a reference to container
, then use querySelector
on container
to get each button, which saves having to search the DOM continuously?
Or is it indifferent?