r/shittyprogramming • • Jul 12 '22

Button element in div

Hey guys

I am trying to create buttons via. javascript and appending these to the div container using a for loop.

It works when i append with document.body.append(button) but when i try to make it append the div, it does not work.

Can you help me with what i am doing wrong?

let div = document.getElementsByTagName("div");

for(let i = 1; i<100 ; i++){

let button = document.createElement("BUTTON");

button.innerHTML = 'hey ';

div.append(button);

}

// the html is just a simple body with h1 and div

4 Upvotes

10 comments sorted by

View all comments

Show parent comment

3

u/cmd-t Jul 12 '22

Seriously how do people find this sub, look at the name, and then think ‘this is where I should ask my question’

2

u/bwgarlick Jul 13 '22

Shouldn't you be on stackoverflow with all this complaining about what was asked and where it's posted?