Debuggin’ the DOM Tree

Rhino beetle on tree

Share This Post

In the past, I have written about ways to debug, which, in most cases, incorporates using the inspection tool built into modern browsers. That is definitely a cool tool and the one I use the most. With that said, I want to talk a bit today about debugging the DOM and how you can even use the DOM to debug itself.

With the HTML DOM, it does not take long to get things complex. We need to be able to dissect…or slice and dice…things up to fix any bugs. You have seen the usage of alerts, the console, document.writes and breakpoints. Here is another tip…

Utilize the DOM itself to tell you what is happening…

createElement() can be used within the DOM to ‘manufacture’ HTML code and then use appendChild to add to it. So what would this look like? Imagine you have an application that changes as the user clicks on buttons, but it is not functioning as intended. You could put an empty div on your page…

<div id="history"></div>

You can then use this div to write content to the page to observe what is happening within the DOM code you construct. Imagine you have a function running and you have code in there that is flow control code (if statements, switch statements, etc.). Within this code, you are attempting to alter the DOM. You can write a function that will record the information to your history div right on your page.

// Update the decision history
var history = document.getElementById("history");
if (someVar!= 0) { // This would be what piece of code you are testing
    // Add the latest info to the history
    var someElem = document.createElement("p");
    someElem.appendChild(document.createTextNode("Description Text: " + aVar+ " -> some more description text" + bVar+ " : " + cVar)); 
        // variables are examples that are pulled from your flow control code
} else {
    // Clear the decision history
    while (history.firstChild)

All this code does is pull information from the flow control code and dynamically create it and stick it into the history div.

Happy Coding!

Clay Hess

More To Explore


Demystifying Scrum User Stories Confirmation: Ensuring Quality and Collaboration

One of the key elements of Scrum is the use of user stories to define the requirements of a system or feature from the perspective of the end user. As teams work through the product backlog, it becomes crucial to confirm the user stories to ensure they meet the desired criteria and are ready for development. In this blog post, we’ll explore the concept of Scrum user stories confirmation and its significance in delivering high-quality products.


The Power of Conversations in Scrum User Stories

At the heart of Scrum lies the concept of user stories, which serve as a means of capturing requirements from the perspective of end-users. However, the true power of user stories lies not just in their written form but also in the conversations that take place around them. In this blog post, we will explore the significance of conversations in Scrum user stories and how they contribute to the success of Agile projects.

Do You Want To Boost Your Business?

drop us a line and keep in touch

Scroll to Top

Need help?

Let's have a chat...


Jump Back In!

Here at Webolution Designs, we love to learn. This includes sharing things we have learned with you. 


Begin Your Learning Journey Today!

Come back inside to continue your learning journey.