I'm attempting to walk the DOM of a page using javascript, and do a simple alert on every tag, to display the tagName attribute. It doesn't seem to be working.
This is the code and the HTML in a jsfiddle (and beow) https://jsfiddle.net/fluffymuffins/fw208ozk/
I don't see any alerts. What's wrong?
HTML
<body>
test text
<p>
some paragraph
</p>
<img src="http://example.com/image.jpg">
</body>
JS
var results = [];
walkDOM(document.body, function(node) {
alert(node.tagName);
});
var walkDOM = function (node,func) {
func(node); //What does this do?
node = node.firstChild;
while(node) {
walkDOM(node,func);
node = node.nextSibling;
}
};