From the course: Vanilla JavaScript: Building on the Document Object Model (DOM)

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Processing comments

Processing comments

- One of the simplest node types for us to format is the common node. You'll see, we have a comment note in our source code here. So let's start by adding a comment note handler to the pretty print function. We'll go back into our editor and go to the pretty print function. And you'll see here that we have our switch statement down here that lets us choose based on the node type to have different handling. So let's do a case node, comment node. So when we receive a comment node, we're going to create a new element. And this element is um going to be called a PP comment element. So comment equals document dot, create element. You know, we have to create elements so we can display them on the screen. So PP comment. And so this is once again a custom tag. And we're going to make the inner text of this comment. The node value of our node. So node node value. So that's the comment text. So the node value. Now we're…

Contents