Skip to content
Advertisement

javascript InnerHTML adding cards only one time

I’m trying to add a bootstrap card inside a div called [itemscontainer] using javascript by document.getElementById("itemscontainer").innerHTML so i want the cards to be inserted inside the itemscontainer only one time like this :-

enter image description here

but the problem is the items cards keeps reapet them salves more than one time like:-

enter image description here

what i want is to clear the itemscontainer first before adding the cards and this is what i have tried so that the items will be only one cards for each item

JavaScript

Advertisement

Answer

The real solution is to figure out why you are getting the items more than once. With the information you provided that is impossible for me to answer. So the only thing we can recommend is how to prevent items from being added more than once.

If your messaging system returns duplicates you can determine if you have seen it. If you do, replace it. Otherwise add it.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement