This is such a basic question that it will probably make me look like an
idiot, but anyway...

I have an element in my document:

<p id="foo">...

I'm writing a new JS function (in a linked JS file), and sending it a
single argument, the ID of an element in the document. My real intention
was to send it as a string, but just for the hell of it, I called the
function without stringifying or "getting" the element first, just using
the bare ID identifier like this:

myNewFunction( foo ) { ...

I thought the function would throw an error ("what's foo?"). But it's not
-- the function is receiving it as a complete reference to the actual
element. I don't understand this, because I did NOT do any of these:

$(foo)
or
document.getElementById("foo")
or anything like that.

I have no idea what's happening... so in Firebug, I tried just typing into
the console:

    foo

And just as in my function, Firebug didn't say "undefined" or throw an
error; it returned a reference to the actual element as though I'd typed
document.getElementById("foo"). Why?

When I asked Firebug what the typeof foo is, it told me it's an HTML
element! How does Firebug know what foo is? I didn't "get" it first!

I tried the same thing in Chrome dev tools, with the same result.

It's hard to figure out what's going on with the function because I'm not
sure what the Console convention (Firebug or Chrome) is. Is there some
convention that, as a "convenience" to you, if you just type in a bare ID,
and run it, the console resolves that to the actual element?

This seems so basic I can't believe I'm confused about this, but I am...
<http://Sanstudio.com>

-- 
You received this message because you are subscribed to the Google Groups 
"Firebug" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/firebug.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/firebug/CAMoMLKiCjrn17io3%3D_ZsFWWWt9hpaXbNANv2i4mmXb_m-kiXEg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to