263Chapter 15Generic HTML Element (Web hosting domains) Objects} } function turnOff()

263Chapter 15Generic HTML Element Objects} } function turnOff() { document.getElementById( myP ).removeBehavior(myPBehaviorID); } function setColor(select, color) { if (document.getElementById( myP ).hotColor) { document.getElementById( myP ).setHotColor(color); } else { alert( This feature is not available. Turn on the Behavior first. ); select.selectedIndex = 0; } } function showBehaviorCount() { var num = document.getElementById( myP ).behaviorUrns.length; var msg = The myP element has + num + behavior(s). ; if (num > 0) { msg += Name(s): rn ; for (var i = 0; i < num; i++) { msg += document.getElementById( myP ).behaviorUrns[i] + rn ; } } alert(msg); }

addBehavior() and removeBehavior() Method Lab



This is a sample paragraph. After turning on the behavior, it will turn your selected color when you mouse down anywhere in thisparagraph.

Choose a hot color:

To turn off the behavior, the removeBehavior()method is invoked. Notice that theremoveBehavior()method is associated with the myPobject, and the parameter is the IDof the behavior added earlier. If you associate multiple behaviors with an object, you canremove one without disturbing the others because each has its own unique ID. elementObject.addBehavior()

Leave a Reply