|
May 21, 2000 Creating Nodes under the DOM Tips: May 2000
Yehuda Shiran, Ph.D.
|
|
The createElement() method creates a stand-alone element under the document object. This element is a single node that has neither children nor father, and is not related to any other existing document nodes. The only information attached to such a node is the HTML tag it represents, such as <P>, <FONT>, or <TABLE>. The HTML tag is the only parameter you need to specify when calling the createElement(). To create a <FONT> tag element, for example, you would write:
A classic exercise for demonstrating the createElement method is to create an HTML table. It is popular for several reasons. First, the table includes quite a few different HTML tags. Then, the TABLE construct is deeply nested (five levels of hierarchy). Last, there is a hidden tag in HTML tables that you need to create explicitly (
Notice again that these four nodes (
Read in Column44, The Document Object Model (DOM), Part 5, how to connect these four isolated nodes.
People who read this tip also read these tips: Look for similar tips by subject: |