Dedicated web hosting - 275Chapter 15Generic HTML Element Objectsthe user has closed

275Chapter 15Generic HTML Element Objectsthe user has closed the window, the conditional expression also sees if the window is closed. Ifit is, a new subwindow is generated, and that new window s reference value is reassigned to thenewWindvariable. On the other hand, if the window reference exists and the window is notclosed, the focus()method brings that subwindow to the front. You can see the focus()method for a text object in action in Chapter 25 s description of theselect()method for text objects. Related Items:window.open(), document.formObject.textObject.select()methods. clearAttributes() Returns:Nothing. Compatibility:WinIE5+, MacIE-, NN-, Moz-, Safari- The clearAttributes()method removes all attributes from an element except the nameandidvalues. Thus, styles and event handlers are removed, as are custom attributes assigned ineither the HTML source code or later by script. You should know that the clearAttributes() method does not alter the length of the element s attributescollection because the collectionalways contains all possible attributes for an element. (See the attributesproperty for ele- ments earlier in this chapter.) This method is handy if you wish to construct an entirely new set of attributes for an elementand prefer to start out with a blank slate. Be aware, however, that unless your scripts immedi- ately assign new attributes to the element, the appearance of the element reverts to its com- pletely unadorned form until you assign new attributes. This means that even positionedelements find their way back to their source code order until you assign a new positioningstyle. If you simply want to change the value of one or more attributes of an element, it isfaster to use the setAttribute()method or adjust the corresponding properties. To accomplish a result in NN6+/Moz1+ that simulates that of IE5+ s clearAttributes(), you must iterate through all attributes of an element and remove those attributes (via theremoveAttribute()method) whose names are other than idand name. ExampleUse The Evaluator (Chapter 13) to examine the attributes of an element before and after youapply clearAttributes(). To begin, display the HTML for the table element on the page byentering the following statement into the upper text field: myTable.outerHTMLNotice the attributes associated with the

tag. Look at the rendered table to see howattributes such as borderand widthaffect the display of the table. Now, enter the followingstatement in the top text box to remove all removable attributes from this element: myTable.clearAttributes() First, look at the table. The border is gone, and the table is rendered only as wide as is neces- sary to display the content with no cell padding. Finally, view the results of theclearAttributes()method in the outerHTMLof the table again: myTable.outerHTMLThe source code file has not changed, but the object model in the browser s memory reflectsthe changes you made. Related Items:attributesproperty; getAttribute(), setAttribute(), removeAttribute(), mergeAttributes(), and setAttributeNode()methods. elementObject.clearAttributes()