Use window.document instead of document.