Get all elements in firefox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sunny

    Get all elements in firefox

    Does anyone knows, how to all the list of all the elements on the web
    page using javascript.
  • Martin Honnen

    #2
    Re: Get all elements in firefox

    Sunny wrote:
    Does anyone knows, how to all the list of all the elements on the web
    page using javascript.
    document.getEle mentsByTagName( '*')
    should give all elements in the document. Assuming "web page" is an HTML
    document and you want the elements in the body then you might only want
    to look in the body e.g.
    document.body.g etElementsByTag Name('*')

    --

    Martin Honnen

    Comment

    • Sunny

      #3
      Re: Get all elements in firefox

      On Oct 3, 12:58 pm, Martin Honnen <mahotr...@yaho o.dewrote:
      Sunny wrote:
      Does anyone knows, how to all the list of all the elements on the web
      page using javascript.
      >
      document.getEle mentsByTagName( '*')
      should give all elements in the document. Assuming "web page" is an HTML
      document and you want the elements in the body then you might only want
      to look in the body e.g.
      document.body.g etElementsByTag Name('*')
      >
      --
      >
      Martin Honnen
      http://JavaScript.FAQTs.com/
      When I do:
      alert(document. getElementsByTa gName('*'));
      It gives me "Object HTML Collection"
      I want to see, all the elements name in my web page.
      As I am creating some elements dynamically, i want the name of all the
      elements present on my webpage.
      And I want to do that in Firefox.
      Any solution.

      Comment

      • Joost Diepenmaat

        #4
        Re: Get all elements in firefox

        Sunny <sunnyluthra1@g mail.comwrites:
        On Oct 3, 12:58 pm, Martin Honnen <mahotr...@yaho o.dewrote:
        >Sunny wrote:
        Does anyone knows, how to all the list of all the elements on the web
        page using javascript.
        >>
        > document.getEle mentsByTagName( '*')
        >should give all elements in the document. Assuming "web page" is an HTML
        >document and you want the elements in the body then you might only want
        >to look in the body e.g.
        > document.body.g etElementsByTag Name('*')
        >>
        >--
        >>
        > Martin Honnen
        > http://JavaScript.FAQTs.com/
        >
        When I do:
        alert(document. getElementsByTa gName('*'));
        It gives me "Object HTML Collection"
        I want to see, all the elements name in my web page.
        Well, yeah.

        var elements = document.getEle mentsByTagName( "*");
        for (var i = 0; i < elements.length ; i++) {
        alert(elements[i]);
        }

        Though I would strongly recommend you install firebug, enable it and do:
        console.debug(e lements);

        then check the console.

        --
        Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

        Comment

        • SAM

          #5
          Re: Get all elements in firefox

          Le 10/3/08 7:09 PM, Sunny a écrit :
          When I do:
          alert(document. getElementsByTa gName('*'));
          It gives me "Object HTML Collection"
          Yes, that is a collection.
          I want to see, all the elements name in my web page.
          What do you call "name" ?
          The name, the id, the tag name ?

          var c = [];
          var d = document.getEle mentsByTagName( '*');
          for(var i=0, n = d.length; i<n; i++) c.push(d[i].tag+Name);
          alert(c.join()) ;

          but that will not give you the hierarchy
          (nor wich ones are imbricated nor in what)
          As I am creating some elements dynamically, i want the name of all the
          elements present on my webpage.
          And I want to do that in Firefox.
          Any solution.
          use the extension 'FireBug'

          --
          sm

          Comment

          • Eric B. Bednarz

            #6
            Re: Get all elements in firefox

            Sunny <sunnyluthra1@g mail.comwrites:
            When I do:
            alert(document. getElementsByTa gName('*'));
            It gives me "Object HTML Collection"
            I want to see, all the elements name in my web page.
            As I am creating some elements dynamically, i want the name of all the
            elements present on my webpage.
            And I want to do that in Firefox.
            As you might have gathered from previous replies, you
            a) need to do something with the collection
            b) it isn’t clear from your description what that would be

            If you just want a list of the used element types, you’d want to
            avoid duplicates and probably sort the result, e.g.

            var list = document.getEle mentsByTagName( '*'),
            l = list.length,
            result = [],
            node;
            while (l--) {
            node = list[l].nodeName;
            if (-1 === result.indexOf( node)) {
            result.push(nod e);
            }
            }
            alert(result.so rt());

            (Joost’s suggestion applies)


            --
            ||| hexadecimal EBB
            o-o decimal 3771
            --oOo--( )--oOo-- octal 7273
            205 goodbye binary 111010111011

            Comment

            Working...