Can we limit document.createElement? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can we limit document.createElement?

Document.createElement creates element. If I had onclick -> createElement, it would keep creating more elements. Can we limit it to how many it can create? Like ... if it reaches certain number, it needs to stop creating.

31st Jul 2019, 6:35 AM
Ginfio
Ginfio - avatar
3 Answers
+ 1
You can simply count up a variable and if it reaches a certain value you either remove the event listener or you block createElement with an if statement.
31st Jul 2019, 6:45 AM
Aaron Eberhardt
Aaron Eberhardt - avatar
0
Aaron Eberhardt can you use the (i) number to limit .createElem.. can h finish this code. https://code.sololearn.com/WmOXxGBkh8p9/?ref=app
31st Jul 2019, 6:55 AM
Ginfio
Ginfio - avatar
0
Here's the fixed code: https://code.sololearn.com/WI1t1G2c3D8B/?ref=app Yet you should keep in mind that removing the event listener would be a cleaner solution for this problem.
31st Jul 2019, 9:41 AM
Aaron Eberhardt
Aaron Eberhardt - avatar