Fixed #1908 by testing to make sure it isn't null before checking the nodeType.