Adding check for node to closest function

I added a check to ensure that the node exists so that if parentNode is null (when html is not in DOM) the method will not raise an exception.