Prevent illegal invocation by avoiding the null parentNode

I was having a problem with using `closest` with a detached DOM fragment. This PR prevents using `matches` with a null element, which causes an illegal invocation.