Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how does getElementsByTagName("*")['id'] work?

    Does the interpreter loop through and compare all id's to find that member, or what?

    <button id="foo" onclick="alert(document.getElementsByTagName('*')['foo']==this?'yes':'no')">Am I foo?</button>

    ...maybe not, because document.getElementsByTagName('*')[this] doesn't do the same...
    *this message will self destruct in n-seconds*

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Or maybe it's more like an object property... DOMelementsWithId={foo:[OBJECT-button#0], blah:[OBJECT-div#2]}...
    *this message will self destruct in n-seconds*

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Hmm, that might work, but it's not anywhere in the DOM specs. So, you really shouldn't do it like that. getElementsByTagName returns a NodeList, and NodeLists only have index access, not key access. (Though implementations are free to extend as long as they don't change the behavior of anything from the spec.)

    IDs must be unique for a document anyway, so why not simply use getElementById?
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #4
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm, another mystery... I wonder if that's at all related to NamedNodeMap...
    *this message will self destruct in n-seconds*

  • #5
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    or maybe...

    that is called internally for the getElementById method.
    Last edited by codegoboom; 08-29-2004 at 07:45 AM. Reason: it was bugging me...
    *this message will self destruct in n-seconds*

  • #6
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    I would think it's written in such a way that it mimics the IE document.all vector, despite not being an exact replica of it according to the DOM specs.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #7
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ...and a more educated guess, at that...

    So why use it?
    For no good reason, really; though if you had to find an element by either unique-id or unique-name (but didn't know which ahead of time), that could work for both.
    *this message will self destruct in n-seconds*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •