Replaced undefined check with null check, for document.getElementById