Summary
In this chapter, you’ve seen different ways of adding markup to a document in the web browser. I’ve shown you some quick examples of the “old school” techniques:
-
document.write
-
innerHTML
I’ve given you more in-depth examples using the DOM methods. The key to using these methods is to see a web document as a tree of nodes.
-
createElement
-
createTextNode
-
appendChild
-
insertBefore
Whenever you use createElement or createTextNode, you are creating a node that floats around in JavaScript limbo. Using appendChild and insertBefore, you can take these DocumentFragments and insert them into the node tree of a document.
You’ve seen the image gallery example refined. Along the way, you’ve seen the construction of a very handy function called insertAfter. You’ll be able to use this function in lots of situations where you need to add markup to a document.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Rights and permissions
Copyright information
© 2005 Jeremy Keith
About this chapter
Cite this chapter
(2005). Creating Markup on the Fly. In: DOM Scripting. Apress. https://doi.org/10.1007/978-1-4302-0062-8_7
Download citation
DOI: https://doi.org/10.1007/978-1-4302-0062-8_7
Publisher Name: Apress
Print ISBN: 978-1-59059-533-6
Online ISBN: 978-1-4302-0062-8
eBook Packages: Professional and Applied ComputingProfessional and Applied Computing (R0)Apress Access Books