menu

arrow_back When you create an element through Jquery are overwritten, how do you make them accumulate?

by
1 vote
When I create an element through setInterval in jQuery, it overwrites every time. How do I make it accumulate?
let startGenerate = $(`#start`);






startGenerate.on(`click`, function(){
setInterval(function(){
let index = Math.floor(Math.random()* 10 + 1);
let newElement = $(`#container`).append(`<div>`).addClass(`element`)
newElement.text(index)
}, 1000);

1 Answer

by
 
Best answer
0 votes
$('<div>').addClass('element').text(index).appendTo('#container')