Adding check for node to closest check so that it will not raise if parentNode is null (not in the DOM).