minimal fixes in clearBeforeUnload

The suggested changes prevent exceptions in case of usage `GridUnload` and recreating the grid with cached (saved in a JavaScript variable) old DOM element of previous grid.