I have 5 <li> elements on page load.
Other <li> elements are added randomly at every number of seconds. I need to remove the <li> elements that have been on the page longer than a minute.
I was thinking of having an attribute called data-created-at which stores the time it was added. And then have a looped function (via js, in the same page) that checks for <li> elements to be removed.
If above is a sound approach. Should I store the time for data-created-at in milliseconds?
Good idea? Or is there a better way to go about this? +1 for anyone who gives a code snippet along with their description.
I’m not sure if this is a better alternative, but couldn’t you just use
setTimeoutto setup a planned destruction of the elements a minute after you create them?There was a request to elaborate, so I’ll do the best I can. This is going to be somewhat psuedocodey.
Where you have defined a function
insert, and a functiondelete, where insert does the actual inserting of your new<li>into your HTML, anddeleteis called after 60 seconds.