What is the best practice for cleaning an html?

Asked

Viewed 54 times

1

I am working with javascript for a short time, and I see people commenting whenever innerHTML is a bad practice.

I agree that it is not a very beautiful code to write htmls by the js themselves, but I have a great habit of using innerHTML to clear a table or list.

The question is, if I’m not going to use innerHTML to clear lists, I need to go through all the nodes I want to delete with a while, and go deleting one by one. In addition to the code getting bigger, I wanted to know in a matter of performance which is more advisable, the pros and cons of both. And if there’s any other way.

1 answer

0

you can use Jquery this way: $('#suaLista li').text(''). In terms of performance the browser will not even feel pain for any of the ways :)

  • some solution for pure js ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.