Adding the content
Adding the content of the
div presents a bit of a problem. I could use the innerHTML property:
but how could I do it using straight DOM methods? The first thought would
be to simply set the value of the text node child of the
The text does indeed get added, but the results might not quite be what you expect, as shown in Figure 4.
The problem is that you're not really adding text, but rather mixed content, consisting of text and elements. The browser assumes that you mean this as CDATA, which is taken literally, and the elements are not created. Rather than simply adding all of the content in one block, you need to actually add each element:Listing 6. Adding the content
First, you've created a new function,
getEditLink, which returns an object. That object is the
a element, which you created using standard DOM methods. Next, you add a standard break tag,
br, and finally, the node that contains the actual note text.
The result is the completed note, with elements intact and ready for use.