Skip to main content

Creating Markup on the Fly

  • Chapter
DOM Scripting
  • 665 Accesses

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

eBook
USD 24.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 34.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Rights and permissions

Reprints 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

Publish with us

Policies and ethics