Be aware that this function doesn't actually understand HTML -- it fixes tag-soup input using the general rules of SGML, so it creates well-formed markup, but has no idea which element contexts are allowed.
For example, with input like this where the first element isn't closed:
<span>hello <div>world</div>
loadHTML will change it to this, which is well-formed but invalid:
<span>hello <div>world</div></span>