r/badcode • Now where's that function declaration • Nov 06 '21

js Something seems off...

Post image
247 Upvotes

31 comments sorted by

View all comments

Show parent comment

29

u/Neitzches Nov 06 '21

You can also use Fragments. Append to a fragment and then when you're done append the fragment to the DOM node.

14

u/sohang-3112 Nov 06 '21

Nice! First time I've heard of this approach. For anyone else seeing this, you can read about DocumentFragment API in JS here

2

u/gu3st12 Nov 06 '21

In the case of this post, you'd need to use a fragment as it's binding an event listener to the button.

1

u/kristallnachte Nov 07 '21

Or just push them to an array and append them all together.

Could use map instead of that stupid loop and then append the result.