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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DOM Attribute Collection

    I've been working on a dynamic script using the DOM and wanted a routine that would parse out the element attribute collection. I came up with a routine that works in FireFox 1.5 and Opera 8, but it doesn't work in IE 6. Any ideas?

    Thanks in advance for your help,
    Dan


    <html>
    <head>
    <title>DOM Element Properties</title>
    <script language="javascript" type="text/javascript">
    function objProp(x) {
    elem = document.getElementById(x);
    document.write(elem.attributes.length + "<br>");
    for (i=0;i<elem.attributes.length;i++) {
    if (elem.attributes[i].specified) { // to handle IE's 'user-specified' attribute collection
    document.write(elem.attributes[i].name + "->" + elem.attributes[i].value + "<br>");
    }
    }
    }
    </script>
    </head>
    <body>
    <img src="http://www.codingforums.com/images/icons/icon2.gif" alt="button0" width="16" height="16" border="0" id="btn0" onClick="objProp('btn0');"/> Click the arrow.
    </body>
    </html>

  • #2
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Using the attributes array instead
    http://wsabstract.com/dhtmltutors/domattribute2.shtml

  • #3
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I thought I was using the attributes array ... elem.attributes[i].name and elem.attributes.value ... is this not true?

  • #4
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ie and ff work
    Code:
    <html>
    <head>
    <title>DOM Element Properties</title>
    <script language="javascript" type="text/javascript">
    function objProp(x) {
    var ieattr=0 //for ie
      elem = document.getElementById(x);
      for (i=0;i<elem.attributes.length;i++) {
         if (elem.attributes[i].specified) { 
             ieattr++;//for ie
                document.write(elem.attributes[i].name + "->" + elem.attributes[i].value + "<br>");
    
                                           }                 
                                              }
         if (document.all){
                     document.write(ieattr);
    				 }
           else{
    	             document.write(elem.attributes.length + "<br>");
    				 }
    
    }
    </script>
    </head>
    <body>
    <img src="http://www.codingforums.com/images/icons/icon2.gif" alt="button0" width="16" height="16" border="0" id="btn0" onClick="objProp('btn0');"/> Click the arrow.
    </body>
    </html>


  •  

    Posting Permissions

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