Skip Navigation

View Page Structure

 
A couple of days ago, I was having a little CSS trouble. In the end, it turned out that I had set a property of an element "above" in the document tree, and the problematic element was inheriting that property.

It struck me that it would be easier to work through this kind of CSS problem with some kind of simple tool to show how a page was put together. If I could see all the tags on the page in a nested format, with parent and child relationships obvious, and without all the text getting in the way, my life would be easier.

So, I put together this tool. In simple terms, it will fetch a page from a web server and output the tags within the page in a nested list. The JavaScript side of it will also highlight children of an element when you hover over it.

Classes and ids attributes are highlighted, as are tag names. Class and ID names, though, must be enclosed in quotation marks to be highlighted. Text, closing tags and line breaks are not shown. Though I can understand some people may find it useful to see text, I found it made the tree too large to be usable.

I've used it a few times, and am quickly finding it saves quite a lot of time solving simple CSS problems or conflicts. Which is exactly what it was supposed to do. Enjoy!

Highlighting Issues


When writing the tool, I came across a fairly unusual problem. I wanted, when the mouse was over an element, to highlight its children. However, this cannot be done with CSS (at least, I couldn't think of a way to make it work).

The problem with the CSS was that whenever you hover over an element, you are also hovering over its parents. So they, and their children, are highlighted - meaning everything is highlighted. For this reason, the highlighting of elements uses JavaScript.

How to Use


The page structure tool is written to accept a URL either by GET or POST. You can therefore use it one of two ways.

First, you can use the tool by visiting the URL below, replacing "##url##" with the address of the page you want to view:

http://www.ilovejackdaniels.com/view_structure.php?url=##url##

Alternatively, you can use the following form to submit an address to the page:



Bookmarklet


To make life a little easier, I've coded a quick JavaScript bookmarklet for you to use, that, when activated, will automatically submit the URL of the page you are viewing to the tool. Simply copy or drag the link below to your links bar, your favourites folder or anywhere else you wish:

Notes


  • This tool works best with valid code, especially XHTML.
  • A certain amount of basic code improvement is done before processing (for example all empty tags are automatically closed).
  • Sites with non-empty tags that aren't closed properly may not show up correctly.
  • Sites with large amounts of nested code should still show up, but it may be difficult to view the output.

Example


If you want to see an example of the output of this tool, you can view the structure for ILoveJackDaniels.com.
 

Syndication

If you like this post, subscribe to my full feed or partial feed.

 

24 comments (Add Yours)

You can keep up to date with this discussion by subscribing to the RSS or Atom feed.
 
very cool and nicely done !
Hey good idea. It's an interesting alternative to Dom inspector and web dev tools for firefox. I tried it out on a few sites and was quite impressed. Thanks!
Thanks Jim and gb.

I have a few ideas for improvements and expansions to it, so will be working on it over time. If you've any ideas for improvements or additions, though, please let me know!
 United States #4: February 22, 2005
Wow, this works great! I will definitely be utilizing this tool next time my code goes wacky on me. Thanks!
Is there an error in the script? This used to work, but now it does not place a border around the elements.
This tool is great for instructional purposes.
Nicely spotted, John, thankyou.

It appears that in a recent edit I deleted the script tag that adds the JavaScript functionality to that page. Oops! Fixed now though :)
Thank God for my love of JD. It directed me to this site and, in turn, to this terrific resource.

TO think I'd been relying on Dreamweaver's poorly rendered views all this time.
A very useful addition is to be able to export the page to PDF or otherwise print it with the elements highlighted in a hierarchy.
bughouse
United States #9: August 2, 2005
check out 'Xyle scope' from http://www.culturedcode.com/
very incredible for debugging CSS. (not to belittle what you have done, which is great!)
washy
Germany #10: August 5, 2005
great tool! i can see now how badly written my page is and fix it ;)
 United Kingdom #11: August 16, 2005
Did you do that with PHP's XML reading tools, I really need help with them... Probably help if I knew how to use XML...
Dear Friend,
The Idea is great as well as the implementation no doubt about. But I think there are some bugs.
I face some problem with the code. I checked a webpage. http://www.herbalbd.com/suman/signup.html
and the result doesn't show me the </title> and </head> tag.Where is the problem?

Coolsaint
Jacksonville Web Design
United States #13: October 15, 2005
Hello,
I came across your site while testing a content filter on my PC... glad I tried a search for "Jack Daniles"... :) You have a very nice site, the "Live Search" thing is absolutely killer as well as this dom inspector you have written. Very nicely done!
Jim S.
Jacksonville, FL
jimsummer@tentonweb.com
Captain Spaulding
United Kingdom #14: December 7, 2005
Excellent stuff. Would be even more excellent if I could use it on my local pages!
mabelle
Philippines #15: December 13, 2005
hi! this is a great tool! :)
Wonderful tool! I'd like to mention that I've been using a very similar tool in the form of a firefox extension that has been invaluable in troubleshooting code. It is called "View Rendered Source" and along with the Web Developer Toolbar makes coding alot less painful :)

https://addons.mozilla.org/extensions/moreinfo.php?id=655&application=firefox
 United States #17: March 12, 2006
Any chance you're gonna give us the source?
Choks ,Infy , India
India #18: July 12, 2006
hey jack , this is really cool . it would be of gr8 help if u could give the source...
Markie1006
United States #19: July 18, 2006
Firefox already has an excellent extension to do this, and more
It's called the "View Formatted Source" extension
Nice and helpful tool. I have already checked some of my sites just to see how it work.
Ron Weihs, Canada
Unknown #21: November 30, 2006
This is so elegant! Congratulations not just on the functionality, but on the design of the tool.
I now love Jack even more. This is brilliant. Well done!!!!
damn! I Love ilovejackdaniels! this rocks
Chad
Australia #24: August 16, 2007
Hi great tool! Is there anyway to make the result "downloadable"?

Thanks!

 

Post Your Comment

 
Only the name and comment fields are required.
 

Live Comment Preview

 United States #25: 1 minute ago

Web Design, Development and Marketing