Refactor empty() to work better on non-IE browsers.

1. Check node.innerHTML rather thatn node.canHaveChildren(), since the latter
only works on IE.
2. Also, limit empty(parent) to orphaning parent's children, rather than orphaning
parent's grandchildren.

Fixes #17869.