added a test case to show what goes wrong, if you undo the fix this test will fail with 'TypeError: Cannot read property 'parentNode' of undefined'