Loading ...
Sorry, an error occurred while loading the content.

Retrieving Attributes from Elements

Expand Messages
  • jasonsfoster
    Hi everyone, Is there an easy way to list out every attribute from a single element, so that I can see what is available for the getAttribute and setAttribute
    Message 1 of 2 , Feb 1, 2005
    • 0 Attachment
      Hi everyone,

      Is there an easy way to list out every attribute from a single
      element, so that I can see what is available for the getAttribute
      and setAttribute methods?

      Thanks in advance.... your help is MUCH appreciated!!!
    • Cameron McCormack
      Hi Jason. ... Yes, you can use the attributes attribute on the Node interface to get a list of attributes that are on the element. var e =
      Message 2 of 2 , Feb 1, 2005
      • 0 Attachment
        Hi Jason.

        jasonsfoster:
        > Is there an easy way to list out every attribute from a single
        > element, so that I can see what is available for the getAttribute
        > and setAttribute methods?

        Yes, you can use the 'attributes' attribute on the Node interface to get
        a list of attributes that are on the element.

        var e = document.documentElement;
        for (var i = 0; i < e.attributes.length; i++) {
        var a = e.attributes.item(i);
        window.alert("attribute " + a.name + " has value " + a.value);
        }

        Have a look at DOM 2 Core for more info:

        http://www.w3.org/TR/DOM-Level-2-Core/core.htm

        Cameron

        --
        e-mail : cam (at) mcc.id.au icq : 26955922
        web : http://mcc.id.au/ msn : cam-msn (at) aka.mcc.id.au
        office : +61399055779 jabber : heycam (at) jabber.org
      Your message has been successfully submitted and would be delivered to recipients shortly.