Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8766973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:41:12+00:00 2026-06-13T16:41:12+00:00

Possible Duplicate: Why can’t I have a direct reference to document.createElement? I am quite

  • 0

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;

  1. However when I call it like var someElement = d("p"); I get “TypeError: Illegal invocation” and I’m not sure what that means.

  2. 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 element someElement = d.e("p") it works.

Can someone explain what causes 1. to fail and why 2. works?
Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:41:14+00:00Added an answer on June 13, 2026 at 4:41 pm

    You need to wrap them in a function so that you can call them from the document object.

    var d = function(name) {
        return document.createElement(name);
    };
    

    This is simply a requirement of the createElement method implementation. It needs to know what document it should be creating the element from.

    When you detach a method from an object, the method has no memory of the original object.

    That’s why this works:

    d.e("p");
    

    Since e is a reference to the createElement method, and it is being called from d, which is a reference to the document, you’re effectively doing the same as:

    document.createElement("p");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can I have a Django model that has a foreign key reference
Possible Duplicate: Can you have multiple $(document).ready(function(){ … }); sections? May be this question
Possible Duplicate: Can you have multiple $(document).ready(function() sections? Is it OK to have multiple
Possible Duplicate: MySQL: Large VARCHAR vs. TEXT? Since VARCHAR can have 65k bytes now,
Possible Duplicate: Can I scroll a ScrollView programmatically in Android? I have a chat
Possible Duplicate: Can Read-Only Properties be Implemented in Pure JavaScript? I have an Object
Possible Duplicate: How can i made a pivot for this I have a table
Possible Duplicate: How can I convert a string to boolean in JavaScript? I have
Possible Duplicate: C++ static virtual members? Can we have a static virtual functions? If
Possible Duplicate: Interfaces: Why can't I seem to grasp them? I have seen many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.