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.

8<br />

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

canHaveHTML<br />

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

Compatibility ✓<br />

Example<br />

Use The Evaluator (Chapter 13 in the <strong>JavaScript</strong> <strong>Bible</strong>) to experiment with the<br />

canHaveHTML property. Enter the following statements into the top text field and<br />

observe the results:<br />

document.all.input.canHaveHTML<br />

document.all.myP.canHaveHTML<br />

The first statement returns false because an INPUT element (the top text field<br />

in this case) cannot have nested HTML. But the myP element is a P element that<br />

gladly accepts HTML content.<br />

childNodes<br />

elementObject.childNodes<br />

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

Compatibility ✓ ✓ ✓<br />

Example<br />

The walkChildNodes() function shown in Listing 15-3 accumulates and returns<br />

a hierarchical list of child nodes from the point of view of the document’s HTML<br />

element (the default) or any element whose ID you pass as a string parameter. This<br />

function is embedded in The Evaluator so that you can inspect the child node<br />

hierarchy of that page or (when using evaluator.js for debugging as described in<br />

Chapter 45 of the <strong>JavaScript</strong> <strong>Bible</strong> ) the node hierarchy within any page you have<br />

under construction. Try it out in The Evaluator by entering the following statements<br />

into the top text field:<br />

walkChildNodes()<br />

walkChildNodes(getElementById(“myP”))<br />

The results of this function show the nesting relationships among all child nodes<br />

within the scope of the initial object. It also shows the act of drilling down to further<br />

childNodes collections until all child nodes are exposed and catalogued. Text nodes<br />

are labeled accordingly. The first 15 characters of the actual text are placed in the<br />

results to help you identify the nodes when you compare the results against your<br />

HTML source code. The early NN6 phantom text nodes that contain carriage returns<br />

display in the results for each return character.

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

Saved successfully!

Ooh no, something went wrong!