There are a couple of ways you can fix this. Ultimately you need to check the target to make sure nothing is in the <div> before you move the image. The first way to do this is with .innerHTML.

...