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.

270<br />

HR.align<br />

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

invokes the same setHRAttr() function, passing a reference to itself so that the<br />

function can inspect details of the element. Figure 5-1 shows the page after several<br />

choices have modified the HR element.<br />

Figure 5-1: Modifying HR element properties<br />

The first task of the setHRAttr() function is to make sure that only browsers<br />

capable of treating the HR element as an object get to the meat of the function. As<br />

the page loads, the document.all property is set for NN6 using a normalization<br />

technique described in Chapter 14 of the <strong>JavaScript</strong> <strong>Bible</strong>.<br />

For suitably equipped browsers, the function next reads the string from the<br />

value property of the SELECT object that is passed to the function. If a selection is<br />

made (that is, other than the first, empty one), then the single, nested statement<br />

uses the setAttribute() method to assign the value to the attribute whose name<br />

matches the name of the SELECT element.<br />

Listing 19-2: Controlling HR Object Properties<br />

<br />

<br />

HR Object Properties<br />

<br />

// document.all normalization trick for NN6<br />

if (navigator.appName == “Netscape” && parseInt(navigator.appVersion) >= 5) {<br />

document.all = document.getElementsByTagName(“*”)<br />

}<br />

// one function does all!<br />

function setHRAttr(select) {

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

Saved successfully!

Ooh no, something went wrong!