Chapter 14. Manipulating the DOM

This chapter covers

  • Injecting HTML into a page
  • Cloning elements
  • Removing elements
  • Manipulating element text

If we were to open up a JavaScript library, we’d certainly notice (most likely with some surprise) the length and complexity of the code behind simple DOM operations. Even presumably simple code, like cloning or removing a node (which both have simple DOM counterparts, like cloneNode() and removeChild()), have relatively complex implementations.

This raises two questions:

  • Why is this code so complex?
  • Why do I need to understand how it works if the library will take care of it for me?

The most compelling reason is performance. Understanding how DOM modification works in libraries can allow you to ...

Get Secrets of the JavaScript Ninja now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.