SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 32 | Next

Jonathan Snook, Aaron Gustafson, Stuart Langridge, and Dan Webb

"Accelerated DOM Scripting with Ajax, APIs, and Libraries"

In the following
code example, the loadGallery function still runs, even though the function is declared
after the function call:

In the following example, you??™ll get an error message because the first script element is
evaluated and executed before the second one:


My general approach is to include as much of my code in functions and load them in
from external files first; then I run some code to start the whole thing up.
Embedding Code Properly into an XHTML Page
Embedding JavaScript on an HTML page is easy enough, as you saw in the previous examples.
Many online examples usually include HTML comment tags to hide the JavaScript from
browsers that don??™t recognize JavaScript.

CHAPTER 1 n THE STATE OF JAVASCRIPT 5
However, the days of someone using a browser that doesn??™t recognize JavaScript are long
gone, and HTML comments are no longer necessary.
XHTML, however, is a different beast. Because it follows the rules of XML, the script has to
be enclosed into a CDATA block, which starts with .

nNote Throughout the book, I??™ll be using HTML almost exclusively; if you prefer to use XHTML, you??™ll need
to keep this in mind.


Pages:
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44