spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column75


Netscape 6, Part IV: DOM Differences and Commonalities with IE5.x

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Creating Document Fragments

Netscape 6 supports the DOM's createDocumentFragment() method. This method creates a new node, like the createNode() method. We put the following script in the HEAD section of this page:

<SCRIPT LANGUAGE="JavaScript">
<!--
if (document.all) {
}
else if (document.layers) {
}
else if (document.getElementById) {
  fragObj = document.createDocumentFragment();
}
// -->
</SCRIPT>

The type of the node created by createDocumentFragment() is 11. Other typical type numbers are 1 for a tag node, 2 for an attribute node, and 3 for a text node. Click this button in Netscape 6, and see for yourself. Click in Internet Explorer and observe the error message:

Here is the code for this button:

<INPUT TYPE="button" VALUE="What's fragObj.nodeType?"
  onClick="javascript:alert('fragObj.nodeType =
   ' + fragObj.nodeType)">

One way to distinguish between a fragment node and regular node is that it does not have a parent (parentNode is null.) Examine its parent now:

Here is the code for this button:

<INPUT TYPE="button" VALUE="What's fragObj.parentNode?"
  onClick="javascript:alert('fragObj.parentNode =
   ' + fragObj.parentNode)">

Still, it belongs to the document. Examine its owner document:

Here is the code for this button:

<INPUT TYPE="button" VALUE="What's fragObj.ownerDocument?"
  onClick="javascript:alert('fragObj.ownerDocument =
   ' + fragObj.ownerDocument)">

Finally, examine its name:

Here is the code for this button:

<INPUT TYPE="button" VALUE="What's fragObj.nodeName?"
  onClick="javascript:alert('fragObj.nodeName =
   ' + fragObj.nodeName)">

In order to add the fragment node to the DOM tree, you must explicitly call one of the node insert methods — insertBefore, replaceChild, or appendChild.

Next: How to use the innerHTML property, browser-independently

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: January 15, 2001
Revised: January 15, 2001

URL: http://www.webreference.com/js/column75/7.html