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

  • Home
  • SEARCH
  • 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 1025137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:52:59+00:00 2026-05-16T11:52:59+00:00

I mean a wrap function like this: function $(id) { return document.getElementById(id); } but

  • 0

I mean a wrap function like this:

function $(id) { return document.getElementById(id); }

but in some code like this:

oDiv1 = $("postInfoDiv");
oDiv2 = document.getElementById("postInfoDiv");
alert(oDiv1 == oDiv2);                     // return false
alert(oDiv1.style);                            // error
alert(oDiv2.style);                            // correct
alert(document.getElementById("postInfoDiv").style); // correct

I got strange results as the comments imply.
I thought the first alert should return the true since they are the same dom object.
I thought the second alert should alert something like “object” or “CSS StyleDeclaration” but not “defined”.

So what are the problems? Have you ever met this kind of problems?

thanks.

  • 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-05-16T11:53:00+00:00Added an answer on May 16, 2026 at 11:53 am

    Your $ function is probably being overridden, potentially by a framework.

    You should try doing alert( oDiv1.nodeType ) to see if it’s a DOM element. alert( oDiv1.length ) to see if it’s an empty array because you may be using jQuery on the same page which overrides your $ function.

    oDiv1 may be an array-like object containing that item if jQuery is included. oDiv2 is an actual DOM reference. You probably need to compare oDiv1[0] to oDiv1, in which you reference the first element in the array which points to the actual dom element to make a fair comparison.

    function $(id){return document.getElementById(id)}
    $('content') == document.getElementById('content')
    true
    

    The custom $ function will work perfectly but if you’re using a framework function it will return that array-like object instead of the DOM element.

    You can also rename your function to something like function getID which would be unique and not conflict with framework $s.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I mean I have this code: <script> $(document).ready( function() { $('html, body').animate({ scrollTop: $(.error).offset().top
I mean something like that: class parentClass { public function method() { echo $this->prop;
I had this code : function (i) { alert(i); }(3); And it wasn't working
I mean something like this: http://www.globalscaletechnologies.com/p-25-sheevaplug-dev-kit-uk.aspx My minimal hardware requirement is: Ethernet card UPDATE:
I'd like to wrap Prototype Ajax.Request in order to simulate AJAX latency. I mean,
For specific debugging purposes I'd like to wrap the del function of an arbitrary
The code is as follows: <body> <a href="javascript:;" id="test">hello</a> </body> <script type="text/javascript"> document.getElementById("test").addEventListener("click", function
I have a Foo constructor like this: function Foo(params) { this.x = params.x +
I mean something like: update table_name set field_1=if(date_add(data_field,interval 30 hour) >= now(),1,0), field_2=if(date_add(data_field,interval 30
I mean things like: FK1 -> 1FK2 -> 2PK Please, note that 1FK2 is

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.