11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

var originalColor;<br />

function activateBackground()<br />

{<br />

}<br />

originalColor = style.backgroundColor;<br />

style.backgroundColor = "yellow";<br />

//-->><br />

<br />

<br />

Notice how the HTC can implicitly access the Style object of the element to which it is bound.<br />

This is because the scoping rules for HTCs dictate that, if the identifier is not found in the<br />

Behavior itself, then the element to which it is attached is the next enclosing scope. If the name<br />

cannot be resolved in the element to which it is attached, the Window in which the element is<br />

defined is checked. Note that you can reference the object to which the Behavior is bound<br />

explicitly using the element identifier, but there is rarely a need to do so in practice.<br />

To expose a public property to the document containing the element to which the Behavior is<br />

bound, a element is used with the name attribute set to the name of the<br />

property. For example, you might include the following in your HTC:<br />

<br />

Elements to which the Behavior is bound can then set this value by setting an activeColor<br />

attribute. Assuming the ―rollover‖ class is bound to your HTC, you might use<br />

Click<br />

me<br />

To see how this might be used, we revisit the previous rollover example, this time including an<br />

onload event handler that sets the activeColor if one was not defined in the element:<br />

<br />

<br />

<br />

<br />

<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!