+ 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

29th Sep 2019, 5:20 AM
Ginfio
Ginfio - avatar
3 Antworten
29th Sep 2019, 5:34 AM
Gordon
Gordon - avatar
+ 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. ..
29th Sep 2019, 5:54 AM
Ginfio
Ginfio - avatar
+ 1
oh yeah, i forgot the appendChild(). I got it now. Thx.
29th Sep 2019, 5:37 AM
Ginfio
Ginfio - avatar