DHTML
  Home arrow DHTML arrow Page 6 - Rough Guide To The DOM (part 2)
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
DHTML

Rough Guide To The DOM (part 2)
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2001-05-09


    Table of Contents:
  • Rough Guide To The DOM (part 2)
  • Making The Swap()
  • Turning The Tables
  • Well-Formed
  • In The Frame
  • Branching Out
  • Dumbing It Down
  • Conclusions

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Rough Guide To The DOM (part 2) - Branching Out
    ( Page 6 of 8 )

    The DOM also comes with a bunch of built-in methods designed to manipulate the DOM tree, adding and removing nodes from it on the fly. As you've already seen, a node on the DOM tree could be either an HTML tag or a text fragment - and the DOM comes with methods to add both these types of nodes to the tree, through program code.

    I'll begin with the createElement() method, which is used to create a new HTML tag. The following code snippet creates an <img> tag as a node, and assigns it the name "imageObj".

    <script language="JavaScript"> var imageObj = document.createElement("img"); </script>

    Once the node has been created, attributes can be assigned to it using the setAttribute() method. For example, the code snippet

    <script language="JavaScript"> imageObj.setAttribute("src", "logo_n.gif"); imageObj.setAttribute("width", "50"); imageObj.setAttribute("height", "50"); </script>

    is equivalent to the tag

    <img src="logo_n.gif" width="50" height="50">

    Once the node has been created, the next order of business is to add it to the document tree - a task accomplished by the appendChild() method. The appendChild() method is used to append the newly-created node to a specific location in the tree.

    The following code snippet would attach the "imageObj" node as a child of the element identified by "heading1".

    <script language="JavaScript"> document.getElementById("heading1").appendChild(imageObj); </script>


    This article copyright Melonfire 2001. All rights reserved.

     
     
    >>> More DHTML Articles          >>> More By Vikram Vaswani, (c) Melonfire
     

       

    DHTML ARTICLES

    - Rough Guide To The DOM (part 2)
    - Rough Guide To The DOM (part 1)
    - Filters And Transitions In IE5
    - Understanding Embedded Fonts




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek