Section 3.27. Frequently Asked Questions?


3.27. Frequently Asked Questions?

Q:

Why didn't we just use form <input> elements for the coffee maker's status? Wouldn't that have been a lot easier than using all this DOM stuff?

A:

We certainly could have used form elements to display the status of the coffee makers. The problem with using form elements, though, is that users expect to be able to type into form fields. The status elements we're using are for display onlyusers are not supposed to change those values themselves. So it makes more sense for them to be non-editable fields that just display text.

That means we have to use the DOM... but as you'll see in the next chapter, the DOM isn't that hard. Once you understand how the browser really sees your HTML markup, you'll be writing your own DOM code in no time. So stay tuned...

Q:

Isn't there a simpler way to get and set the text of a <div>? I've read about a property called "innerHTML," which would let me just put in the HTML I wanted for the <div>. Couldn't we use that instead?

A:

Using the innerHTML property is not a good way to get and set the contents of an element. It's not part of the DOM specification, and the W3C has deprecated itfuture versions of browsers may not even support it. Worse than that, some browsers don't support it now!

It's much safer going with the DOM code we're using here. In the next chapter, we'll get into all the details about how the DOM code works, and once you've written a few functions using the DOM, you'll see it's pretty easy to use. Best of all, the DOM is available anytime you've got a web browser, on any platform.




Head Rush Ajax
Head Rush Ajax (Head First)
ISBN: 0596102259
EAN: 2147483647
Year: 2004
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net