Possible Duplicate:
Why can’t I have a direct reference to document.createElement?
I am quite new to Js and have been playing around with it.
Since document.getElementById
& doucment.createElement
is quite long I have decided to put it in a variable;
eg var d = document.createElement;
However when I call it like
var someElement = d("p");
I get "TypeError: Illegal invocation" and I'm not sure what that means.If I separate the
document
object,var d = document;
and then give that a property like so:d.e = d.createElement;
then use it to create an elementsomeElement = d.e("p")
it works.
Can someone explain what causes 1. to fail and why 2. works? Thank you in advance.