JavaScript and the Document Object Model
Changing existing nodes
Now you have the content, but how can you change it? Because you added elements separately, you can just edit the single text node that represents the text of the note. You can do this three ways. First, you can remove the offending node and add a new one:
Listing 7. Removing the node and adding a replacement
|
Another option is to simply replace the existing node:
Listing 8. Replacing a node
|
In this case, the oldNode
is replaced with the newNode
, and the document changes accordingly.
Finally, you could simply change the text of the existing node:
Listing 9. Changing the existing node
|
Because editNote
takes the id
value of the appropriate div
, the same function can be used for any note, as seen in Figure 5.
View JavaScript and the Document Object Model Discussion
Page: 1 2 3 4 5 6 7 8 Next Page: Summary and ResourcesFirst published by IBM developerWorks