How do you get buttons inside a div only? no jquery
<div class="keys">
<button id="a"></button>
<button id="b"></button>
</div>
I have many buttons, and I want the getones that are inside <div>with class="keys", but I cannot get it to work, so far I have tried:
content = document.getElementsByClassName("keys");
kbButtons = content.getElementsByTagName("button");
and i just get undefined
Notice how the method is called "getElements ...", the plural.
document.getElementsByClassName() returns an HTMLCollection object similar to an array.
content = document.getElementsByClassName("keys")[0];
kbButtons = content.getElementsByTagName("button");
You can access the first element of the HTMLCollection with syntax [0].