Objective

Manually define the textContent property on the Node interface.

Difficulty

Average

Description

As we saw in the previous HTML DOM — The Node Interface chapter, the textContent accessor property of the Node interface returns back the textual content of a given node.

Its value depends on the type of the underlying node:

  • For text and comment nodes, it's just the nodeValue property the node.
  • For element nodes, it's the concatenation of the textContent of each of its children excluding comment nodes.

In this exercise, you have to redefine textContent on the Node interface based on the discussion above.

You don't need to implement textContent in a way such that it takes into account all the different types of nodes. Rather, you only need to consider text, comment and element nodes.

That's it.