HTML parsing errors when the DOM is dynamically updated to new HTML content

I recently started updating my site to send and receive requests / responses through AJAX. I am using a prototype library.

My existing HTML code contains certain imgand tags inputthat are not closed.

When I try to update the content of an element (say div) with such HTML code using the innerHTML property, I get parsing errors such as "unwanted code" or "malformed", etc.

Without using AJAX, i.e. without dynamically updating the DOM, the page functions normally even using non-standard html coding.

Question:

Is there a way to use dynamic updating and still avoid parsing errors?

+3
source share
1 answer

Yes, you can use dynamic updating if you are convinced that your page conforms to standards. JS libraries are designed with this in mind, and they have problems inserting data into pages that do not meet standards. You can probably fix the problem by simply closing the tags.

0
source

Source: https://habr.com/ru/post/1706789/


All Articles