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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.