10.07.2017 Views

246996016-HTML5-Step-by-Step

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Using the <strong>HTML5</strong> Tag 303<br />

call to any number of other places in the code, including within the main .ready() function<br />

call, or within the .submit() function.<br />

There is much, much more to error handling, jQuery, and JavaScript than can be shown<br />

in one short chapter, but with this basic knowledge in hand, you can now explore why<br />

the <strong>HTML5</strong> tag is so important.<br />

Note If you’d like to learn more about JavaScript and jQuery, the book, JavaScript <strong>Step</strong> <strong>by</strong> <strong>Step</strong>,<br />

provides greater detail with regard to everything you’ve seen in this chapter. Additionally, the<br />

jQuery home page at http://www.jquery.com is an excellent resource for learning about jQuery<br />

and all that it can do.<br />

Using the <strong>HTML5</strong> Tag<br />

New in <strong>HTML5</strong> is a tag called , which provides a space on which you can draw<br />

graphics, run animations, and much more within a Web page. However, the <br />

tag, <strong>by</strong> itself, doesn’t do anything. Instead, the tag relies on JavaScript to draw<br />

the graphics it can contain. So you can see that it’s no coincidence that you’ve spent so<br />

much time learning about JavaScript in this chapter!<br />

The tag is one of the easiest tags in <strong>HTML5</strong>. You simply tell the browser how<br />

large you want the canvas area to be, and it creates the container accordingly. For<br />

example, The following example shows a 250 × 250 pixel :<br />

<br />

Unfortunately, as of this writing, many browsers don’t support the element;<br />

therefore, you’ll need to provide alternative content for browsers that aren’t ready for<br />

canvas-based graphics yet. You can provide this alternative content <strong>by</strong> placing it between<br />

the opening and closing tags, like this:<br />

<br />

Alternate content goes here<br />

<br />

Browsers that don’t understand the tag will ignore it and display the contents<br />

of the HTML found within it; in this case, a tag.<br />

You use JavaScript to draw on the canvas, so it’s lucky that you just learned so much<br />

about the language!

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

Saved successfully!

Ooh no, something went wrong!