#Adding HTML content dynamically

5 messages · Page 1 of 1 (latest)

low pecan
#

I'm working on page that has a "to do list". I wanted to know if there is a better way to dynamically add a group of html elements during runtime using JS. For example I want it to create a div with various buttons and text inside it each time I hit a button. So far the only way I know of making this happen is by constructing it piece by piece in JS using .createlement and .appendchild but this method seems way too tedious.

distant fulcrum
#

You could use innerHTML instead, but that is both slower and less secure. The standard approach without using a library/framework is how you have been doing it. One major reason for using a library or framework is to avoid the need for that tedious approach.

low pecan
#

aah i see ill take a look into both templates and libraries

#

thanks guys