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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Moz dynamic attributes

    in IE I can do this:

    HTML
    <a attribute="somevalue">
    js
    alert(document.getElementsByTagName('A').attribute);


    why can't I do that in moz/firefox?

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Because IE doesn't follow the standard!

    The correct way to do this (and this should be in the DOM forum) is as follows:
    Code:
    alert(document.getElementsByTagName('A').item(0).attributes.getNamedItem("attribute").nodeValue);
    At least I'm pretty sure that's the way...

    For more information on this kind of stuff, refer to my favourite API:
    http://krook.org/jsdom/Node.html

    Hope that helps,
    Sadiq.

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moz dynamic attributes

    Originally posted by Garadon
    alert(document.getElementsByTagName('A').attribute);
    getElementsByTagName is a collection - you have to specify the element's index in the collection. Better also to search in lower case:
    Code:
    alert(document.getElementsByTagName('a')[0].attribute);
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    sad69: Why do it more complicated than necessary?
    Code:
    document.getElementsByTagName('a').item(0).getAttribute('attribute')
    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

  • #5
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Because I didn't know about that one! I don't think I've really ever looked at the Element class before...

    Good call though, I'll use that from now on!

    Cheers,
    Sadiq.

  • #6
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ty


  •  

    Posting Permissions

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