Fixing empty DOM error

Checking to ensure element exists before trying to append, otherwise
DOM throws an error.