HTML and CSS Reference
In-Depth Information
EXPLANATION
(
CONTINUED
)
4
A reference to a new
div
is returned.
5
The cloned table is appended to the
div
just below the original table (see Figure 15.26).
6
This is the
div
container for the cloned table.
Figure 15.26
Cloning a table with a unique
id
.
If you want to dynamically remove a post from a blog or an ingredient from an online
recipe, it can be done with the DOM. To delete an element or node from the DOM tree,
we use the
removeChild()
method. This method must be called from the parent node
because you will be removing a child. It takes a reference to the child it will remove as
its only argument. The following examples demonstrate how to dynamically remove
nodes with JavaScript and the DOM. The first example, Example 15.15, removes a
div
and its contents; the second example, Example 15.16, removes paragraphs.