Add guard before accessing target.nodeName

We need to check that target exists before accessing its properties!