Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 3: The Document Object Model > Manipulating the DOM

MANIPULATING THE DOM

You can do more than use the DOM to look at a document. In fact, you can also manipulate it — creating nodes, adding them to the DOM tree, editing nodes, and removing parts of a document for which you have no more use.

In the sections that follow, I show you how to add and remove various parts of a document to and from the DOM.

Creating an Element and Other Nodes

The document object has several methods used to create nodes. I’m covering the creation of element nodes now; read about other nodes in the “Creating Other Types Nodes” section later in this chapter.

To create an element, use the document.createElement() method. This method creates an instance of the element specified by the parameter. For example, to create a p element, use this:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial