I'm trying to make the document reload when a button is clicked. Here's my code:
var e = document.getElementById('a');
e.addEventListener('click',location.reload);
It returns Uncaught TypeError: Illegal Invocation
after e
was clicked. However, the following code works and the document reloaded:
var e = document.getElementById('a');//same thing
e.addEventListener('click',function(){location.reload()});
//warp location.reload inside function -> works!
I don't understand why the first code doesn't work. Can anyone give some explanation? Thanks!