Alert on Every Tag

Alerts with the tag name of every tag in the dom.

by Diego Santana

HTML

<body>
test text
<p>
some paragraph
</p>
<img src="http://example.com/image.jpg">
</body>

JavaScript

var results = [];

var walkDOM = function (node,func) {
        func(node);  //this will invoke the functionToInvoke from arg
        node = node.firstChild;
        while(node) {
            walkDOM(node,func);
            node = node.nextSibling;
        }
};    
    
var functionToInvoke = function(node) {
    alert(node.tagName);
};

walkDOM(document.body, functionToInvoke);