Abyss web server - 276Part IIIDocument Objects Referenceclick() Returns:Nothing. Compatibility:WinIE4+, MacIE4+, NN2+,

276Part IIIDocument Objects Referenceclick() Returns:Nothing. Compatibility:WinIE4+, MacIE4+, NN2+, Moz1+, Safari1+ The click()method lets a script perform nearly the same action as clicking an element. Prior to NN4 and IE4, the click()method invoked on a button did not trigger the onclickevent handler for the object. This has significant impact if you expect the onclickevent han- dler of a button to function even if a script performs the click. For earlier browser versions, you have to invoke the event handler statements directly. Also, just because a script is click- ing a button, not all buttons in all platforms change their appearance in response. For exam- ple, NN4 on the Mac does not change the state of a checkbox when clicked remotely. If you want to script the action of clicking a button, you can safely invoke the resultingevent handler function directly. And if the element is a radio button or checkbox, handle thechange of state directly (for example, set the checkedproperty of a checkbox) rather thanexpect the browser to take care of it for you. ExampleUse The Evaluator (Chapter 13) to experiment with the click()method. The page includesvarious types of buttons at the bottom. You can click the checkbox, for example, by enter- ing the following statement in the topmost text field: document.myForm2.myCheckbox.click() If you use a recent browser version, you most likely can see the checkbox change statesbetween checked and unchecked each time you execute the statement. Related Item:onclickevent handler. cloneNode(deepBoolean) Returns:Node object reference. Compatibility:WinIE5+, MacIE5+, NN6+, Moz1+, Safari1+ The cloneNode()method makes an exact copy of the current node object. This copy does nothave a parent node or other relationship with any element once the copy exists (of course, theoriginal node remains in place). The clone also does not become part of the document s objectmodel (the node tree) unless you explicitly insert or append the node somewhere on the page. The copy includes all element attributes, including the idattribute. Because the value returnedby the cloneNode()method is a genuine Nodeobject, you can operate on it with any Nodeobject methods while it is still in the non-document object state. The Boolean parameter of the cloneNode()method controls whether the copy of the nodeincludes all child nodes (true) or just the node itself (false). For example, if you clone aparagraph element by itself, the clone consists only of the raw element (equivalent of the tagpair, including attributes in the start tag) and none of its content. But including child nodesmakes sure that all content within that paragraph element is part of the copy. This parameteris optional in IE5 (defaulting to false), but it is required in other W3C-compatible browsers. ExampleUse The Evaluator (Chapter 13) to clone, rename, and append an element found in TheEvaluator s source code. Begin by cloning the paragraph element named myPalong with allof its content. Enter the following statement into the topmost text field: a = document.getElementById( myP ).cloneNode(true) elementObject.click()