SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Non-Member DelvarWorld's Avatar
    Join Date
    Jul 2004
    Location
    Baloney
    Posts
    341
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DOM elements in IE have too many attributes

    Presented with this code:

    Code JavaScript:
    for(var x=0; x<element.attributes.length; x++) {
    	document.write(element.attributes[x] + '<br />');
    }

    There is a big difference between IE and FF as to what is returned. If you do it on an element like this:
    Code XML:
    <div class="mydiv" id="myid"></div>
    ...the aforementioned for loop will return "mydiv" and "myid" in Firefox, which is desired for me. But IE returns every possible attribute, like "$family", "getDocument", including things added by the framework I'm using, MooTools, like "addEvent."

    Is there a way to limit the attributes to what's actually specified in the DOM source, not just everything that's defined?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    See http://www.quirksmode.org/dom/w3c_core.html

    To summarize:

    Firefox and IE8 have issues
    IE5-7 get it really wrong

    Do yourself a favour and don't use the indexed attributes array
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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