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.

6<br />

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

behaviorUrns<br />

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

Compatibility ✓ ✓<br />

Example<br />

The following function is embedded within a more complete example of<br />

IE/Windows HTML behaviors (Listing 15-19 in this chapter). It reports the length of<br />

the behaviorUrns array and shows — if the values are returned — the URL of the<br />

attached behavior.<br />

function showBehaviors() {<br />

var num = document.all.myP.behaviorUrns.length<br />

var msg = “The myP element has “ + num + “ behavior(s). “<br />

if (num > 0) {<br />

msg += “Name(s): \r\n”<br />

for (var i = 0; i < num; i++) {<br />

msg += document.all.myP.behaviorUrns[i] + “\r\n”<br />

}<br />

}<br />

alert(msg)<br />

}<br />

canHaveChildren<br />

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

Compatibility ✓ ✓<br />

Example<br />

Listing 15-2 uses color to demonstrate the difference between an element that can<br />

have children and one that cannot. The first button sets the color style property of<br />

every visible element on the page to red. Thus, elements (including the normally<br />

non-childbearing ones such as HR and INPUT) are affected by the color change.<br />

But if you reset the page and click the largest button, only those elements that can<br />

contain nested elements receive the color change.<br />

Listing 15-2: Reading the canHaveChildren Property<br />

<br />

<br />

canHaveChildren Property<br />

<br />

elementObject.canHaveChildren

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

Saved successfully!

Ooh no, something went wrong!