Re-using DOM elements

When using jQuery to dynamically create elements such as list items, divisions, and input, it can be useful to be able to re-use these elements without having to rewrite them within JavaScript. Instead, it may be beneficial to copy the elements and just modify the sections you wish to change.

Getting ready

Using the text editor of your choice, create a blank HTML document named recipe-12.html, which is within a location that has easy access to the latest version of jQuery.

How to do it…

Learn how to re-use DOM elements by performing each of the following recipe steps:

  1. Within the recipe-12.html page you have just created, add the following HTML, CSS, and JavaScript code:
    <!DOCTYPE html> <html> <head> <title>Reusing DOM elements</title> ...

Get jQuery 2.0 Development Cookbook 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.