+1

JS how to create elements and give them different innerHTML?

So first we create element under onclick event. Now how do we give them different inner HTML values? Maybe increment a number and every time you click "+" (add), The first element.inneHTML will be "1"; The second elm.innerHTML will be "2"; Third will be "3"; ..... Kind of like that. Give every new element new HTML text. ? https://code.sololearn.com/WLEY6oTEjP9b/?ref=app

9/29/2019 5:20:00 AM

Ginfio

4 Answers

New Answer

+5

you also need appendChild https://code.sololearn.com/W0dEL7sP29qH/?ref=app

+3

What about like this: var big = doc...createElement("div"); something.appendChild(big); var small = doc...createElemenet("input"); big.appendChild(small); Now we have inputs inside the divs we're creating. ------- Now add another botton to update the big.innerHTML || innerText. meaning: with "+" it creates big elem, we're also creating input inside the big div everytime we click"+". The update button would be for: when you click on it the inputs would disappear, and what ever is in the inputs would be printed on the big divs. ..

+2

The elements is created but it not show on page So you have to append the element on body or document

+1

oh yeah, i forgot the appendChild(). I got it now. Thx.