You are previewing Secrets of the JavaScript Ninja.

Secrets of the JavaScript Ninja

Cover of Secrets of the JavaScript Ninja by John Resig and Bear Bibeault Published by Manning Publications
O'Reilly logo

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 ...

The best content for your career. Discover unlimited learning on demand for around $1/day.