0

Is there a tool/utility I can attach to a browser that can literally scan over all the objects on a given page and spit out a readable stack of elements? Or is there a means I can even make one with jQuery or something?

What I want to have or do is find literally all the elements between the body tags and list them out grouping them where ever possible. So I can build a document for my team and keep track of whats where, etc for down the road when we need to revisit stuff.

chris
  • 36,115
  • 52
  • 143
  • 252
  • 3
    All the DOM inspectors will allow you to view the entire DOM hierarchy. Chrome, Safari and Opera have a DOM inspector built-in. Firebug is an add-on for Firefox. I don't know of a tool that lets you print it. – jfriend00 Dec 19 '11 at 21:26

4 Answers4

1

Most browsers have developer tools. Press F12 in IE and Chrome, not sure for Firefox.

enter image description here

Ash Burlaczenko
  • 24,778
  • 15
  • 68
  • 99
1

Firebug, Firefox tool bar, IE tool bar (F12), Chrome Dev tools (F12 again...), there's lots and lots of DOM inspector tools out there (or already built in the browser)

Mike Sav
  • 14,805
  • 31
  • 98
  • 143
1

If you'd just like a list of all the elements on the page (and their children up to one level), try this:

$("body").find("*").each(function(){
    document.write( this.nodeName.toLowerCase() + "<br>" )
    if( $(this).children().length > 0 ){
        $(this).children().each(function(){
            document.write( "<ul>" );
            document.write( "<li>" + this.nodeName.toLowerCase() + "</li>" );
            document.write( "</ul>" );
        }); 
    }
});

Example.

However, this answer provides a much better method and lists all of an element's children.

Community
  • 1
  • 1
Purag
  • 16,941
  • 4
  • 54
  • 75
1

The developer tools built into most browsers will show you the entire DOM in its current state. You can also live edit the DOM (both structure and CSS).

A couple other handy tidbits of info:

In Chrome (and I believe also Firebug) you can click on an element in the DOM (so it is highlighted), then in the console view, whatever you selected can be reached with '$0'. They also include a nice copy() function which puts that DOM text onto the clipboard, ready to be pasted into a text editor:

  1. In "Elements view, click an element (e.g. the <body> tag).
  2. Click over to Console

    copy($0)
    
  3. Open a text-editor, and paste.

See also:

print($0)

http://code.google.com/chrome/devtools/docs/console.html

Malcolm Dwyer
  • 1,145
  • 8
  • 9