15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

48 <strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

title<br />

elementObject.title<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓ ✓ ✓<br />

Example<br />

You can see how dynamic a tooltip is in Listing 15-17. A simple paragraph element<br />

has its TITLE attribute set to “First Time!”, which is what the tooltip displays<br />

if you roll the pointer atop the paragraph and pause after the page loads. But<br />

an onMouseOver event handler for that element increments a global variable<br />

counter in the script, and the title property of the paragraph object is modified<br />

with each mouseover action. The count value is made part of a string assigned to<br />

the title property. Notice that there is not a live connection between the title<br />

property and the variable; instead, the new value explicitly sets the title property.<br />

Listing 15-17: Controlling the title Property<br />

<br />

<br />

title Property<br />

<br />

// global counting variable<br />

var count = 0<br />

function setToolTip(elem) {<br />

elem.title = “You have previously rolled atop this paragraph “ +<br />

count + “ time(s).”<br />

}<br />

function incrementCount(elem) {<br />

count++<br />

setToolTip(elem)<br />

}<br />

<br />

<br />

<br />

title Property Lab<br />

<br />

<br />

Roll the mouse over this paragraph a few times.<br />

Then pause atop it to view the tooltip.<br />

<br />

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

Saved successfully!

Ooh no, something went wrong!