Javascript

Topic: JS HTML DOM

What is the disadvantages using innerHTML in JavaScript?

 If you use innerHTML the content is replaced everytime. We cannot use like 'appending to innerHTML'. Even if we use += like "innerHTML = innerHTML + ‘html’" then also the old content is replaced by html. If we use innerHTML then the entire innerHTML content is re-parsed and build into elements. Therefore it’s much slower. The innerHTML doesn't provide validation and therefore we can potentially insert invalid and broken HTML in the document and break it.

Browse random answers: