0

If I make an AJAX call that returns a chunk of HTML, will everything in that chunk of HTML work properly if I add it to the page by assigning it to an element's innerHTML or outerHTML?

Due to past experiences, I've always been under the impression that it's better to manually add to the DOM by using things like document.createElement() instead of simply assigning a blob of HTML to innerHTML or outerHTML.

I'm under the impression that nuanced bugs may arise when assigning strings of HTML to innerHTML or outerHTML. Is there any merit to this concern?

Edit: I edited my question to emphasize that I want to know if innerHTML or outerHTML has any known bugs. The duplicate doesn't cover this.

Ryan
  • 5,883
  • 13
  • 56
  • 93
  • 1
    My take is if you trust the source then the fastest and most readable is likely innerHTML and template literals. – mplungjan Aug 23 '23 at 19:55

0 Answers0