On clicking add button , div is duplicated .How to edit code so that each added div element has unique id.eg: 3rd add btn id b13 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

On clicking add button , div is duplicated .How to edit code so that each added div element has unique id.eg: 3rd add btn id b13

https://code.sololearn.com/Wm7q2XZ0vl9M/?ref=app

15th Jan 2018, 5:11 PM
muhammed rizwan
muhammed rizwan - avatar
3 Answers
+ 1
Add a variable, increase it each time you click add button and add it's value to the new div id. Add to body "<div id=\"div"+i+"...
15th Jan 2018, 5:32 PM
Petr Leliaev
Petr Leliaev - avatar
0
how ? can you explain the code ?
15th Jan 2018, 5:39 PM
muhammed rizwan
muhammed rizwan - avatar
0
Something like this. I added a bit to your code. Each time you click the button new divs will have ID's div1, div2, div3, etc. https://code.sololearn.com/W589x2YJxkuI/?ref=app
16th Jan 2018, 5:55 AM
Petr Leliaev
Petr Leliaev - avatar