create window from a button

when first time button click, it create window and i attach it to div object.

but when close the window, and at same page clicked on button error

Result of expression ‘create’ [[object HTMLDivElement]] is not a function.

When the window is closed, it is removed with ites content. You may hide a window instead of closing it: