Can I assign document.getElementById to variable in javascript [duplicate]
问题 This question already has answers here : Why can't I directly assign document.getElementById to a different function? (5 answers) Closed 2 years ago . I think document.getElementById is a function. So this function can be assigned to variable. Like this var hello = document.getElementById; console.log(hello('hello'))); <div id="hello">hello</div> But It occurred error like this: Uncaught TypeError: Illegal invocation 回答1: The issue is context. When you take the reference to the function, you