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 />

Second Item<br />

<br />

<br />

Enter some text to add/replace in the list:<br />

<br />

<br />

<br />

<br />

<br />

<br />

The final part of the demonstration uses the removeChild() method to peel<br />

away all children of the UL element until just the two original items are left standing.<br />

Again, the lastChild property comes in handy as the restore() function keeps<br />

removing the last child until only two remain. Upon restoring the list, IE5/Mac fails to<br />

render the list bullets; but in the browser’s object model, the UL element still exists.<br />

applyElement(elementObject[, type])<br />

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

Compatibility ✓ ✓<br />

Example<br />

To help you visualize the impact of the applyElement() method with its different<br />

parameter settings, Listing 15-22 enables you to apply a new element (an EM<br />

element) to a SPAN element inside a paragraph. At any time, you can view the<br />

HTML of the entire P element to see where the EM element is applied, as well as its<br />

impact on the element containment hierarchy for the paragraph.<br />

After you load the page, inspect the HTML for the paragraph before doing anything<br />

else. Notice the SPAN element and its nested FONT element, both of which<br />

surround the one-word content. If you apply the EM element inside the SPAN element<br />

(click the middle button), the SPAN element’s first (and only) child element<br />

becomes the EM element; the FONT element is now a child of the new EM element.<br />

Listing 15-22: Using the applyElement() Method<br />

<br />

<br />

applyElement() Method<br />

<br />

function applyOutside() {<br />

var newItem = document.createElement(“EM”)<br />

newItem.id = newItem.uniqueID<br />

document.all.mySpan.applyElement(newItem)<br />

Continued<br />

57<br />

elementObject.applyElement()

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

Saved successfully!

Ooh no, something went wrong!