15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 1 ✦ Generic HTML Element Objects (Chapter 15)<br />

<br />

This is the first cell<br />

This is the second cell.<br />

<br />

<br />

<br />

<br />

<br />

<br />

outerHTML<br />

outerText<br />

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

Compatibility ✓ ✓ ✓<br />

Example<br />

The page generated by Listing 15-13 (IE4+/Windows only) contains an H1 element<br />

label and a paragraph of text. The purpose is to demonstrate how the outerHTML<br />

and outerText properties differ in their intent. Two text boxes contain the same<br />

combination of text and HTML tags that replaces the element that creates the<br />

paragraph’s label.<br />

If you apply the default content of the first text box to the outerHTML property<br />

of the label1 object, the H1 element is replaced by a SPAN element whose CLASS<br />

attribute acquires a different style sheet rule defined earlier in the document.<br />

Notice that the ID of the new SPAN element is the same as the original H1 element.<br />

This allows the script attached to the second button to address the object. But this<br />

second script replaces the element with the raw text (including tags). The element<br />

is now gone, and any attempt to change the outerHTML or outerText properties of<br />

the label1 object causes an error because there is no longer a label1 object in<br />

the document.<br />

Use this laboratory to experiment with some other content in both text boxes.<br />

Listing 15-13: Using outerHTML and outerText Properties<br />

<br />

<br />

outerHTML and outerText Properties<br />

<br />

Continued<br />

35<br />

elementObject.outerHTML

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

Saved successfully!

Ooh no, something went wrong!