4 Mounting and destroying the virtual DOM

 

This chapter covers

  • Creating HTML nodes from virtual DOM nodes
  • Inserting HTML nodes into the browser’s document
  • Removing HTML nodes from the browser’s document

In chapter 3, you learned what the virtual Document Object Model (DOM) is and how to create it. You implemented the h(), hString(), and hFragment() functions to create virtual nodes of type element, text, and fragment, respectively. Now it’s time to learn how to create the real DOM nodes from the virtual DOM nodes and insert them into the browser’s document. You achieve this task by using the Document API, as you’ll see in this chapter.

When the view of your application is no longer needed, you want to remove the HTML nodes from the browser’s document. You’ll learn how in this chapter as well.

4.1 Mounting the virtual DOM

 

4.1.1 Mounting virtual nodes into the DOM

 
 
 

4.1.2 Mounting text nodes

 
 
 
 

4.1.3 Mounting fragment nodes

 
 
 

4.1.4 Mounting element nodes

 

4.1.5 Adding event listeners

 

4.1.6 Setting the attributes

 
 
 
 

4.1.7 A mountDOM() example

 
 
 
 

4.2 Destroying the DOM

 
 
 

4.2.1 Destroying a text node

 
 

4.2.2 Destroying an element

 
 
 

4.2.3 Destroying a fragment

 
 

Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage