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 9291113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:34:23+00:00 2026-06-18T20:34:23+00:00

I would like to call some functions by shorter alias in order to minimize

  • 0

I would like to call some functions by shorter alias in order to minimize code size.

(function(){
    var t = document.getElementById;
    t('element-id');
})();

This piece of code gives Error: Could not convert JavaScript argument. Why?

  • 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-18T20:34:24+00:00Added an answer on June 18, 2026 at 8:34 pm

    When you assign a function to a different variable, it’s this value changes. Since getElementById expects this to be an element, you’re getting an error.

    If you’re in an environment where you can use bind, use it:

    (function(){
        var t = document.getElementById.bind(document);
        t('element-id');
    })();
    

    This’ll ensure that t‘s this will stay the document object.


    If you can’t use bind, you’ll have to create an intermediary function:

    (function() {
        function t (id) {
            document.getElementById(id);
        }
        t('element-id');
    })();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to call some functions from a Fortran shared library in Python.
I would like to bind some new events and call some functions on a
I want to declare some php functions and i would like to call those
I want to wrap every function call with some logging code. Something that would
I have some classes(call it Class A) which I would like to unit test
I would like to call JavaScript function many time . I have tried like
In order to make bundle work on its own i would like to call
I have a vector of pointers. I would like to call a function for
Suppose I have some functions (say B1,B2,B3,etc...) which call the same function A, I
I would like keep reusing some functions I've created on many of my django

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.