The W3C DOM (level 1) provides JavaScript applications a standard way to access all the elements of the document. In order for JavaScript to change the style of a document dynamically, the HTML tags must be represented as objects. We have already discussed the hierarchical tree-like structure of the document object model in Chapter 11, "The Document Objects: Forms, Images, and Links." 15.4.1 How the DOM Works with NodesNow we will take the DOM to a new level. Just as we used the DOM to access forms, images, and links as objects, now we can use the DOM to access every element in an HTML document. The standard DOM level 1 currently consists of two parts : the DOM core and the DOM HTML (see http://www.w3.org/TR/REC-DOM-Level-1/introduction.html). The DOM core specifies a standard way to manipulate document structures, elements, and attributes; the DOM HTML just extends that functionality to HTML. Recall that the DOM represented an HTML document as a tree: with the DOM, every HTML element can be defined as part of the tree, as shown in Figure 15.23. Figure 15.23. The tree-like hierarchy of the document object model.
The purpose of the hierarchal tree is to provide a logical structure to represent a document and a way to navigate that structure, and to add, modify, or delete elements and content from it. Starting with the document at the top of the tree, you can traverse down the tree to every element until you reach the element, attribute, or text you are seeking. The core DOM identifies each element in the tree as a node object. There are parent and child nodes, sibling nodes, and more (see Table 15.10). Table 15.10. Some DOM objects.
The DOM views every HTML element shown in Figure 15.24 as a node. In the tree, the top node is the <html> tag, called the root node of the document. Below it are the <head> and <body> tags, which are called child nodes of the HTML element. In the <title> is the text My Title, which is also a node, called a text node . Since it is the last node, the tree-like structure terminates at that node, also called a leaf node . The nodes are divided into three types of nodes: the element node , attribute node , and the text node . These types are numbered 1, 2, and 3, for element, attribute, and text node, respectively. In the example, the <title> and </title> tags are element nodes, and the text between the tags, My Title , is an example of a text node. An attribute node is represented as a property of the HTML element to which it is assigned. The <a> tag has an href attribute. In the example, <a href="http://www.prenhall.com">, href is an attribute node and the URL is called its nodeValue . (The text nodes are not supported on all browsers.) Figure 15.24. The node hierarchy.
Refer to Tables 15.11 and 15.12 for a list of node properties and node methods . Table 15.11. Node properties.
Table 15.12. Node methods.
SiblingsA sibling is a node on the same level as another node. In the example, <p> <em>this is </em>some <b>text</b> </p> the parent node is <p> and has two children, the <em> node and the <b> node. Since the <em> and <b> are at the same level within the text, they are called siblings, like brother or sister nodes. Parents and ChildrenWhen looking at the structure of the tree hierarchy, some nodes are above others. A node above another node is a parent node, and the ones below the parent node are its children. See Figure 15.25. Any HTML tags that have both an opening and a closing tag are always parent nodes, for example, <p> and </p> . Figure 15.25. Tree hierarchy of nodes.
Attributes of an element are not child nodes, but are considered to be separate nodes in their own right. For example, the href attribute of the <a> tag is an attribute node, not a child of the <a> tag. The nodeName and nodeType PropertiesWhen walking down DOM tree, you can find out the name of a node and the type of the node with the nodeName and nodeType properties. Table 15.13 gives the value for each of the properties. Table 15.13. nodeName and nodeType properties.
Example 15.22<html> <head><title>The Nodes</title></head> <body><font size="+2"> <h1>Walking with Nodes</h1> <p>Who knows what node?</p> 1 <script name="javascript"> 2 var Parent= document.childNodes[0] ; 3 var Child= Parent.childNodes[0] ; document.write("The parent node is: "); 4 document.write( Parent.nodeName +"<br>"); document.write("The first child of the parent node is: "); 5 document.write( Child.nodeName +"<br>"); document.write("The node below the child is: "); 6 document.write( Child.childNodes[0].nodeName +"<br>"); document.write("The text node below title is: "); 7 document.write( Child.childNodes[0].childNodes[0].nodeName +" <br>"); document.write("The first child of the parent is: "); 8 document.write( Parent.firstChild.nodeName +"<br>"); document.write("The last child of the parent is: "); 9 document.write( Parent.lastChild.nodeName +"<br>"); document.write("The node below the body is: "); 10 document.write( Parent.lastChild.childNodes[0].nodeName + "<br>"); document.write("The next sibling of the h1 element is: "); 11 document.write( Parent.lastChild.childNodes[0].nextSibling. nodeName ); document.write("<br>The last child's type is: "); 12 document.write( Parent.lastChild.nodeType ); </script> </body> </html> EXPLANATION
Working with the ElementsAs you know, an HTML document is largely a set of elements, enclosed in < >, called tags. H2 is an element, <H2> is a tag. The DOM is represented as a hierarchal tree of these elements, where each element is represented as a node. But walking with the nodes is just too much trouble most of the time, so the W3C DOM provides additional methods and properties to help make the walk easier. Table 15.14. HTML element properties to represent HTML attributes.
15.4.2 All Those DOMsYou will often hear terms, like the Netscape DOM, the IE DOM, and the standard DOM. Before the W3C was able to create a standard, fourth-generation browsers introduced their own DOMs. Netscape 4, for example, implemented a layer DOM to control the positioning and visibility of elements, whereas Internet Explorer provided the all DOM to control positioning, visibility, and appearance of elements. They were not compatible and when you created a page, you had to perform cross-browser checking to determine which DOM should be used. This book addresses the W3C DOM, which has been embraced by most modern browsers, including NN6+ and IE5+. [2]
All browsers that comply with the W3C's DOM should implement the ID method for accessing the elements in a document. (See the next section for details.) Here is a little test code you can run to see if your browser is W3C DOM compliant: isNetScape = (document.layers) ? true:false; isInternetExplorer = (document.all) ? true: false; if (document.getElementById){ alert("DOM compliant!"); // Netscape 6+ and IE5+ Go to http://developer.apple.com/internet/javascript/sniffer.html to see examples of "browser sniffer" programs ”programs that can tell what browser is being used. The getElementById() MethodAll that node stuff can be really tricky and vary on different browsers, but by combining the HTML id attribute with the getElementById() method of the document object, it is much easier to get a handle on any HTML object. The getElementById() method returns a reference to the HTML element that can then be manipulated by a JavaScript program. Suppose you have a <body> tag defined with an id attribute, as: <body id="bdy1"> Now in JavaScript you can reference the body element with the getElementById() method as follows : bdyreference = document.getElementById("bdy1") Before the DOM was standardized, Internet Explorer (version 4+) provided another mechanism for accessing all HTML elements within the document, called the all property of the document object. The statement shown above written for IE could be written: bdyreference = document.all["bdy1"]; And Netscape 4 provided yet another format: bdyreference = document.layers["bdy1"] Starting with IE5+ and NN6+, the W3C's getElementID() method is used rather than the all or the layers property. The newer browsers support the W3C standardized DOM although many Web pages were written using the older formats. Example 15.23<html> <head><title>The Dom and Id's</title></head> 1 <body id="body1"> 2 <h1 id="head1">Heading Level 1</h1> 3 <p id="para1"> This is a paragraph </p> </body> <script name="javascript"> 4 var h1tag=document.getElementById("head1"); 5 var bodytag=document.getElementById("body1"); 6 var paratag = document.getElementById("para1"); 7 h1tag.style.fontFamily="verdana"; h1tag.style.fontSize="32"; paratag.style.fontSize="28"; paratag.style.color="blue"; bodytag.style.backgroundColor="pink"; 8 document.write( document.getElementById("body1" )+"<br>"); document.write( document.getElementById("head1") +"<br>"); document.write( document.getElementById("para1") +"<br>"); </script> </body> </html> EXPLANATION
The getElementsByTagName() MethodTo reference a collection of elements, such all the <p> tags, <h1> tags, or <a> tags in your document, you can use the getElementsByTag Name() method. This method takes the name of the element as its argument and returns a list of all the nodes of that name in the document. If you need to collectively change the values of a particular element, such as all the links in an <a> tag, do this by manipulating the reference returned by the getElementsByTagName(). Example 15.24<html><head><title>Working with Tags</title> </head> <body bgcolor=lightblue> 1 <h1> First</h1> <h1> Second</h1> <h1> Third</h1> <font size="+2"> 2 <script language="JavaScript"> var heading1=document.getElementsByTagName("h1"); 3 document.write( heading1 + "<br>"); document.write("There are "+ 4 heading1.length + " H1 tags.<br>"); </script> </body> </html> EXPLANATION
15.4.3 Scrolling with the NodesAlthough the title of this section may sound more like a title for a Star Trek drama, it is really about dynamic HTML. By using the getElementById() method and a little node knowledge, a scrolling marquee is created in Example 15.25. In Chapter 10 we saw scrolling in the window's status and title bar. Now we can scroll within the body of the document. In the following example, a message will continuously scroll across the screen. The original message is placed within a <div> container. By first identifying the HTML div element ” getElementById() ”JavaScript can then reference its child node, which is the text of the message ( firstChild ). This is depicted in Figure 15.29. Example 15.25<html><head><title>Scrolling Text</title> <style> 1 #div1 { background-color:darkgreen; color: white; font-family:courier; font-weight: bold; position:absolute; border-style:groove; border-color:white; padding-left:10px; top:20px; left:10px; 2 width: 595px; height: 6%; 3 overflow: hidden; } 4 img { position: absolute; top: 10px;left:60px; border-style:solid;border-color="darkgreen";} </style> <script language="JavaScript"> <!-- 5 /*Modification of text box marquee by Dave Methvin, Windows Magazine */ 6 var scroll_speed = 200 ; // 200 milliseconds var chars = 1; 7 function init(){ divElement=document.getElementById("div1"); } 8 function scroller() { 9 window.setTimeout('scroller()',scroll_speed); 10 var msg=divElement.firstChild.nodeValue; 11 divElement.firstChild.nodeValue = msg.substring(chars) + msg.substring(0,chars); } 12 scroller(); //--> </script> </head> 13 <body bgcolor="#669966" onLoad="init() ";> <img src="BubyanIsland.JPG" width="450" length="500"> 14 <div id="div1"> The latest news from Baghdad is not good tonight. Sand and rain are hindering our troops. The number of refugees continues to increase in the north... </div> </body> </html> Figure 15.29. Referencing a child node requires first identifying the div element.
EXPLANATION
15.4.4 The style Object and CSSThe style object contains a set of properties corresponding to the CSS attributes supported by your browser. Each HTML object has a style property (starting with IE4 and NN6) used to access the CSS style attributes assigned to it; for example, an H1 element may have been defined with a CSS font-style, color , and padding . The style object has properties to reflect each of the CSS atributes. See Table 15.15. Many of the CSS style attributes, such as background-color, font-size , and word-spacing , contain hyphens in their names . Like all objects we have seen in JavaScript, there is a convention for spelling the name of the object. The name would not contain a hyphen, and multiple words after the first word are usually capitalized. Therefore, the CSS naming convention is different with the properties of the style object. The hyphen is removed and the first letter of each word after the hypen is capitalized. For example, the CSS attribute, background-color, when used as a style property, is spelled backgroundColor, font-size is fontSize, and border-right-width is borderRightWidth. FORMAT elementname.style.property="value"; Example: div2.style.fontFamily = "arial"; Table 15.15. style object properties.
Example 15.26<html> <head><title>Changing Background Color Dynamically</title> 1 <script language="JavaScript"> 2 function bodyColor(){ 3 var i = document.form1.body.selectedIndex; 4 bodycolor = document.form1.body.options[i].value; 5 document.getElementById("bdy").style.backgroundColor = bodycolor; } </script> </head> 6 <body ID="bdy"> <p> Pick a background color for this page. </p> 7 <form name="form1"> <b> Color </b> 8 <select name="body" onChange="bodyColor();"> <option value="pink">pink</option> <option value="lightblue">blue</option> <option value="yellow">yellow</option> <option value="lightgreen">green</option> </select> <br> </form> <p> This is a test. </p> </body> </html> EXPLANATION
Positioning Text with the style PropertyBy assigning a position to the style property it is possible to place an element in different sections of the page. In the following example, by assigning positions , the text is moved after the document has been loaded. Example 15.27<html><head><title>Positioning</title> 1 <script language="javascript"> var div1,div2,div3; 2 function init(){ 3 div1=document.getElementById("first"); div2=document.getElementById("second"); div3=document.getElementById("third"); } 4 function movePosition(){ 5 div1.style.left = 50; div1.style.top = 150; 6 div2.style.left = 100; div2.style.top = 100; 7 div3.style.left = 150; div3.style.top = 50; } </script> </head> 8 <body onLoad="init()"> <font size="+2"> 9 <div id="first" style="position:absolute; top:50px">one</div> <div id="second" style="position:absolute; top:100px">two</div> <div id="third" style="position:absolute; top:150px">three</div> <form> <input type="button" value="move text" 10 onClick="movePosition()"> </form></body> </html> EXPLANATION
Now we will change the position values in the program, as shown in Example 15.28. The output is shown in Figure 15.33. Example 15.28(See Example 15.27 for the complete program.) function movePosition(){ div1.style.left = 50; div1.style.top = 50; div2.style.left = 100; div2.style.top = 100; div3.style.left = 150; div3.style.top = 150; } Figure 15.33. After changing the x,y positions in the program.
Changing Color with the className PropertyThe className property is defined for all HTML elements. With the className property, you can change an element dynamically by assigning it the name of a class defined in a CSS. The following example contains a cascading style sheet with three classes. Example 15.29<html><head><title>Coloring Text</title> <style type="text/css"> body { background-color: yellow; font-size: 22pt; font-weight: bold; } 1 .red { color:rgb(255,0,0); /* Defining classes */ font-style: verdana; font-size: 32; } 2 .blue { color:blue; font-style: verdana; font-size: 36; } 3 .green { color: green; font-style: verdana; font-size: 40; } </style> <script language="javascript"> 4 function init(){ div1=document.getElementById("first"); div2=document.getElementById("second"); div3=document.getElementById("third"); } 5 function colorText(){ div1.style.left = 50; div1.style.top = 50; 6 div1.className="red"; div2.style.left = 100; div2.style.top = 100; 7 div2.className="blue"; div3.style.left = 150; div3.style.top = 150; 8 div3.className="green"; } </script> </head> 9 <body onLoad="init()"> <div id="first" style="position:absolute; top:50px">It's a one,</div> <div id="second" style="position:absolute; top:100px">and a two,</div> <div id="third" style="position:absolute; top:150px">and three!</div> <form> <input type="button" value="move and color text" 10 onClick="colorText()"> </form> </body> EXPLANATION
Figure 15.34. The initial appearance of the document (left); after clicking the button, the color, position, and size of the text is changed (right).
15.4.5 Event Handling and the DOMWe have been discussing events since Chapter 1. They are what allow the program to react to user-initiated events. After browsers got to their fourth version, the events became full-fledged objects. The event object has knowledge about the event: what caused it, what triggered it, where it occured on the screen, and even the parent of the tag that triggered it. The event object, like other objects, has a collection of properties and methods associated with it. Not all browsers support the same event model and not all browsers refer to the event in the same way or even use the same properties. Trickling and BubblingThe way that the events are captured differs by the browser. In Netscape 4, for example, the event comes to life at the window level and is sent down the tree of nodes until it finally reaches the target object for which it was intended; whereas with IE the event springs to life for the target it was intended to affect, and then sends information about the event back up the chain of nodes. With Netscape 4, the event trickles down from the top to its target, and with the IE approach the event bubbles up from its target. Handling the way events propagate is another browser compatibility issue. The W3C DOM level 2 provides an Events module that allows the DOM nodes to handle events with a combination of these methods, but defaults to the bubble up propagation model. This is supported by Netscape 6+, but not IE 6. There are a number of event types defined by the DOM HTML Events module, as shown in Table 15.16. Table 15.16. Event properties.
In the following example, mouseOver and mouseOut events will be used to change the style of a block of text to give it emphasis. When the mouse rolls over a specific block of text, the event handler invokes a function that can check to see what block of text the mouse is on and detect when it leaves the box. The node where the event occurred can be found in the currentTarget property (NN) or the fromElement property (IE). Example 15.30<html><head><title>Positioning</title> 1 <link rel=stylesheet type="text/css" href="externstyle.css"> <script language="javascript"> function init(){ div1=document.getElementById("first"); div2=document.getElementById("second"); div3=document.getElementById("third"); } 2 function colorText(e){ 3 if(e.currentTarget.id == "first") { // Use e.fromElement.id (IE6) 4 div1.className="red"; } else if(e.currentTarget.id == "second"){ div2.className="blue"; } else{ div3.className="green";} } 3 function unColorText(e){ if(e.currentTarget.id == "first"){ // use e.srcElement.id (IE6) div1.className="black"; } else if(e.currentTarget.id == "second"){ div2.className="black"; } else{ div3.className="black"; } } </script> </head> <body onLoad="init()"> 4 <div id="first" style="position:absolute; top:50px" 5 onMouseover="unColorText(event);" 6 onMouseout="colorText(event);">Roll over me! </div> <div id="second" style="position:absolute; top:100px" onMouseover="unColorText(event);" onMouseout="colorText(event);">and then me,</div> <div id="third" style="position:absolute; top:150px" onMouseover="unColorText(event);" onMouseout="colorText(event);">and me too.</div> </body> </html> EXPLANATION
15.4.6 Back to the z-index and Dynamic PositioningIn the CSS section of this chapter, the zIndex property was described to create a three-dimensional effect with a stack of <div> containers. In the following example a JavaScript program manipulates the containers so that they can be moved into different positions. Example 15.31<html><head><title>layers</title> <script language="JavaScript"> 1 function moveUp(id){ 2 var box= document.getElementById(id); 3 if(box.style.zIndex == 100){ // Can't stack higher than 100 4 box.style.zIndex=2; } 5 else if(box.style.zIndex != 3){ box.style.zIndex=100; } else{ 6 box.style.zIndex=0; } } </script> </head> <body bgcolor=lightgreen> 7 <span id="red" style="position: absolute;z-index:0; background-color:red; width:200; height:250; top:50px; left:160px;" 8 onClick="moveUp(id);" ></span> 9 <span id="yellow" style="position: absolute;z-index:1; background-color:yellow; width:90; height:300; top:20px; left:210px;" onClick="moveUp(id); "></span> 10 <span id="blue" style="position: absolute;z-index:2; background-color:blue; width:250; height:100; top:125px; left:134px;" onClick="moveUp(id); "></span> 11 <span id="white" style="position: absolute;z-index:3; background-color:white; width:50; height:50; top:140px; left:230px;" onClick="moveUp(id); "></span> </body> </html> EXPLANATION
15.4.7 Setting VisibilityThe visibility property lets you hide an object and then bring it back into view. You can also use the visibility property to determine the state: it "visible" or "hidden"? [3] This property is useful when creating interfaces such as drop-down menus , slide shows, and pop-ups such as extra text to explain a link or image map. [4]
Drop-Down MenusDrop-down menus are commonly used in Web pages to create submenus that appear and then disappear when no longer needed. The following example demonstrates the use of the visibility property to create this type of menu. When the user clicks on one of the links in the main menu, a drop-down menu will appear. If he double-clicks anywhere within the drop-down menu, it will be hidden from view. Each of the drop-down menus is defined within a <div> container. Example 15.32<html><head><title>Drop-Down Menu</title> <style type="text/css"> 1 a { font-family: verdana, arial; color: darkblue; font-weight: bold; margin-left: 4px; } /* link style for main menu */ 2 #menu, .menu { font-stye: verdana; font-size:10pt; color:black; } /* link style for drop-down menu */ 3 #menu { position:absolute; top:40px; border-style:solid; border-width:1px; padding: 5px; background-color:yellow; width:75px; color: black; font-size: 12pt; 4 visibility:hidden; } 5 #menu2 { position:absolute; top:40px; left:3.2cm; border-style:solid; border-width:1px; padding: 5px; background-color:orange; width:80px; color: black; font-size: 12pt; visibility:hidden; } 6 #menu3 { position:absolute; top:40px; left:6.2cm; border-style:solid; border-width:1px; padding: 5px; background-color:pink; width:80px; color: black; font-size: 12pt; visibility:hidden; } 7 </style> <script language="JavaScript"> 8 function showMenu(id){ 9 var ref = document.getElementById(id); 10 ref.style.visibility = "visible"; // Make the drop-down // menu visible } 11 function hideMenu(id){ 12 var ref = document.getElementById(id); 13 ref.style.visibility = "hidden"; // Hide the drop-down menu } </script> <body bgColor="lightblue"> 14 <table width="350" border="2" bgcolor="lightgreen" cellspacing="1" cellpadding="2"> <tr> <td width="100"> 15 <div id="menu" onDblClick="hideMenu('menu');"> 16 <a class="menu" href="#"> US </a><br> <a class="menu" href="#"> World </a><br> <a class="menu" href="#"> Local </a><br> </div> 17 <a href="#" onClick="showMenu('menu');">News</a> </td> <td width="100"> 18 <div id="menu2" onDblClick="hideMenu('menu2');"> 19 <a class="menu" href="#"> Basketball </a><br> <a class="menu" href="#"> Football </a><br> <a class="menu" href="#>"> Soccer </a><br> </div> 20 <a href="#" onClick="showMenu('menu2');">Sports</a> </td> <td width="100"> 21 <div id="menu3" onDblClick="hideMenu('menu3');"> <a class="menu" href="#"> Movies </a><br> <a class="menu" href="#"> Plays </a><br> <a class="menu" href="#>"> DVD's </a><br> </div> <a href="#" onClick="showMenu('menu3');">Entertainment</a> </td> 22 </tr></table> </body> </html> EXPLANATION
Tool TipsWhen a user's mouse rolls over a section of text or an image, a little tool tip might appear as a little rectangular box of text to give helpful hints or clues to clarify the presentation. And when he moves his mouse away from the area, the tool tip will disappear. You can use the HTML title attribute to create simple tool tips, or you can create your own by taking advantage of the CSS visibility property and JavaScript event handlers. Example 15.33<html><head><title>A tool tip</title> <style type="text/css"> 1 #divclass { font-size:12pt; font-family: arial; font-weight: bold; background-color:aqua; border:thin solid; width: 210px; height:40px; 2 visibility: hidden; /* Can't see the container */ position:absolute; top: 50px; left: 175px; 3 z-index: 1; /* Put the div container on top */ } 4 a { font-family: cursive; font-size: 18pt; font-weight: bold; color:white; position: absolute; left: 60px; } 5 img { position:absolute; top: 50px; z-index:0; } </style> <script language = "JavaScript"> var div1; 6 function init(){ div1=document.getElementById("divclass"); } 7 function showHideTip(e) { 8 if(e.type == "mouseover") div1.style.visibility="visible"; 9 else if(e.type == "mouseout"){ div1.style.visibility="hidden"; } } </script> </head> 10 <body bgcolor=black onLoad="init() ;"> 11 <a href="http://www.servant.xxx" 12 onMouseover="showHideTip(event);" 13 onMouseout="showHideTip(event);" >At Your Service! </a> <br> 13 <img src="waiter.gif"> 14 <div id="divclass">Always tip me at least 20%!</div> </body> </html> EXPLANATION
15.4.8 Simple AnimationAnimation on a Web page can be either captivating and attractive or just plain annoying. It all depends on the design. Whether you are creating banners, slide shows, or animated logos, buttons , or icons, they are attention getters. With dynamic HTML you can create your own animations. There are a number of programs available for this, such as Macromedia Fireworks, Stone Design's GIFfun for Mac OS X, and Adobe Photoshop. The following example takes four GIF images and with the help of a timer, rapidly displays an increasingly smaller image on different positions of the screen, giving the sensation of simple animation ”a green balloon rising into the sky. Example 15.34<html><head><title>balloon</title> <script language="JavaScript"> var position, up, upper, uppermost, upperupmost; function init(){ 1 var position = 1; 2 var up = new Image(); up.src="greenballoon.gif"; 3 var upper = new Image(); upper.src="greenballoon2.gif"; var uppermost = new Image(); uppermost.src="greenballoon3.gif"; var upperupmost=new Image(); upperupmost.src="greenballoon4.gif"; ball = document.getElementById("balloon"); } 4 function move() { 5 if ( position == 1){ document.balloonimg.src=up.src; ball.balloon.style.left = 50; ball.balloon.style.top = 200; 6 position = 2; } 7 else if (position == 2){ document.balloonimg.src=upper.src; ball.style.left = 100; ball.style.top = 150; position = 3; } } else if (position == 3){ document.balloonimg.src=uppermost.src; ball.style.left = 150; ball.style.top = 100; position = 4; } else if (position == 4){ document.balloonimg.src=upperupmost.src; ball.style.left = 200; ball.style.top = 10; position = 1; } } </script> </head> 7 <body bgColor="silver" onLoad="init();"> 8 <span id="balloon" style="position:absolute; left:10; top:250"> <img name="balloonimg" src="greenballoon.gif" > </span> <form> <input type="button" name="move" value=" Move " 9 onClick="startMove=setInterval('move()',900);"> <input type="button" name="stop" value=" Stop " onClick="clearInterval(startMove);"> 10 </form> </body> </html> EXPLANATION
|