Skip to content
Advertisement

JavaScript: Replace list from array by clicking next

How can I replace the whole list without adding new li’s to the list?

I think I should “reboot” it somehow, but I’m not sure how. I could just do it by filling empty li’s in the HTML file, but then I’ll have a problem when there are more or less items.

JavaScript
JavaScript

Thanks!

Advertisement

Answer

While using innerHTML to clean the list is effective, using a proper removeChild is not only arguably more idiomatic but also faster (although the performance will not matter for such small lists). It can be just:

JavaScript

Here is your code with that line:

JavaScript
JavaScript
Advertisement