Web server hosting - 155Chapter 15 .Generic HTML Element Objects Example (with

155Chapter 15 .Generic HTML Element Objects Example (with Listing 15-22) on the CD-ROM Related Items: insertBefore(), appendChild(), insertAdjacentElement() methods. attachEvent( eventName , functionRef) detachEvent( eventName , functionRef) Returns: Boolean. NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5 Compatibility The attachEvent() method is used primarily within code that specifies IE behaviors (see Chapter 48). But you can also use it in regular scripting as yet another way to bind an event handler to an object. The following example characterizes the more typical approach to assigning an event handler: myObject.onmousedown = setHilite The version with attachEvent() is as follows: myObject.attachEvent( onmousedown , setHilite) Both parameters are required. The first parameter is a string version (caseinsensitive) of the event name. The second is a reference to the function to be invoked when the event fires for this object. A function reference is an unquoted, case-sensitive identifier for the function without any parentheses (which also means that you cannot pass parameters in this function call). There is a subtle benefit to using attachEvent() over the event property binding approach. When you use attachEvent(), the method returns a Boolean value of true if the event binding succeeds. IE triggers a script error if the function reference fails, so don t rely on a returned value of falseto catch these kinds of errors. Also, there is no validation that the object recognizes the event name. If you have used attachEvent()to bind an event handler to an object s event, you can disconnect that binding with the detachEvent() method. The parameters are the same as for attachEvent(). The detachEvent() method cannot unbind events whose associations are established via tag attributes or event property settings. The W3C DOM event model provides functionality similar to these IE-only methods: addEventListener()and removeEventListener(). Example on the CD-ROM On the CD-ROM On the CD-ROM elementObject.attachEvent()
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

Leave a Reply