spacer

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

home / experts / javascript / column45


A DOM-Based Sliding Puzzle (5)

Developer News
HP to Microsoft: Thanks for Nothing
iPhone Remains Left Out as Android Scores Flash
The Year of Living the OpenSocial

Building the DOM Tree

As you saw from the main script, building the DOM tree is based on two functions: addOneRow() and addBR(). The addOneRow() function adds one row to the puzzle:

function addOneRow() {
  for (i=0; i < 3; i++) {
    tempSquareNode = squareNode.cloneNode();
    divNode.appendChild(tempSquareNode);
  }
}

The function is based on cloning and appending. First we clone the squareNode node that we created in the main script:

tempSquareNode = squareNode.cloneNode();

Once we have a new node, tempSquareNode, we append it to the DIV containter node, divNode:

divNode.appendChild(tempSquareNode);

The function just loops three times over the above cloning-appending pair, once per a puzzle square in a row. Cloning and appending nodes is explained in detailed in Column 43.

The addBr() function is very similar to the addOneRow() function above, except that it does the cloning-appending pair just once:

function addBr() {
  tempBrNode = brNode.cloneNode();
  divNode.appendChild(tempBrNode);
}

The cloning here is after the brNode node that we created in the main script. Of course, we could have created these nodes from scratch using the createElement() function, as we created the nodes brNode and squareNode in the main script.

http://www.internet.com

Produced by Yehuda Shiran and Tomer Shiran

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

webref The latest from WebReference.com Browse >
Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script · Book Review: Content Rich
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Building Command Line Utilities with Python · fring Brings Mobility to Junction Networks' OnSIP · Another Big Win for Wi-Fi Positioning


Created: August 2, 1999
Revised: August 2, 1999

URL: http://www.webreference.com/js/column45/build.html