I'm trying to declare a variable for some elements using 'document.getElementsByClassName' and I know that this returns a list of nodes but I don't know how to call that out in code. I need all the elements with the particular class name to be called in that var. I have added some div tags with class attributes for example.
If I had ids, this is how my code would be:
var texttop = 150;
var textleft = 150;
var h1 = document.getElementById('h1'); //Similarly, I want to declare var using class name method for classes
function movedown(amount) {
texttop += amount;
h1.style.top = texttop + 'px'; //does this 'h1' also change to something like "forEach((element) => element.style.top"?
}
<input type='button' class="down arrow" onclick='movedown(20)' value=">">
<div id='h1' style='position:absolute;'> some text </div>
<div class="demo"> Hello </div>
<div class="demo"> Bye </div>