Executing
var q = document.querySelector;
q("div");
throws a TypeError: Illegal Invocation exception. Why is that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
because the querySelector method requires an instance of document to work on. you can call
Which says run the method, with this = document
To elaborate, the reason you are getting the error is because if you don’t use the above syntax ‘this’ inside that function will refer to ‘window’. The function must have some form of checking to ensure that ‘this’ is of type document.