bug 6158; fixing replaceWith from throwing errors on empty elements