You can throw away innerHTML and replace it with the new setHTML(), which has a built-in sanitizer. Here's how it works:
HTML Sanitizer API - Web APIs | MDN

The HTML Sanitizer API allows developers to take strings of HTML and filter out unwanted elements, attributes, and other HTML entities when they are inserted into the DOM or a shadow DOM.

MDN Web Docs
@firefoxwebdevs awesome! Now we only have to wait for "baseline" πŸ˜‰
@xela hopefully it won't be too long! Just Safari to go
@firefoxwebdevs Fantastic! Can’t wait for this to be in baseline!
@firefoxwebdevs this is fantastic! This has bitten me in the past, and I'm excited to be able to use this soon!

@firefoxwebdevs Looks great but why is it called setHTML? What is the β€˜set’ supposed to mean?

#WebDev #HTML

@LeonardoDiOttio I see what you're getting at, but replaceChildrenWithParsedHTML is a bit long.

Fwiw when you set innerHTML you're not really setting the HTML either.