Sams Teach Yourself HTML, CSS & JavaScript Web Publishing in One Hour a Day

(singke) #1
ptg16476052

552 LESSON 19: Using JavaScript in Your Pages


Q In what cases might you want to use JavaScript without a library like
JavaScript?
A If your JavaScript is very simple, it may be worth it to leave out supporting librar-
ies. But for most web developers, starting with a tool that accounts for differ-
ences between browsers is a great way to avoid bugs and get things done quickly
and simply. It’s generally better to make use of these sorts of libraries to write
JavaScript from scratch. It’s a good idea to know how to write JavaScript without
libraries, but using them almost always makes sense.

Quiz



  1. What happens whenever a user clicks a link, button, or form element on a web
    page?

  2. In an event handler, what does this refer to?

  3. What kinds of nodes on a page can be associated with properties like nextChild
    and previousChild?

  4. How does form validation with JavaScript conserve server resources?


Quiz Answers



  1. Whenever a user clicks a link, a button, or any form element, the browser generates
    an event signal that can be captured by one of the event handlers mentioned in the
    previous lesson.

  2. In event handlers, this is a reference to the element on which the event was called.
    So in an event handler for the onclick event of a link, this would refer to the link
    that the user clicked on.

  3. Nodes in the DOM can include HTML elements, text inside HTML elements, and
    even whitespace between elements.

  4. JavaScript enables you to do error checking in forms on the browser side before
    the form is ever submitted to the server. A script must access the server before
    it can determine the validity of the entries on a form. (Note that even if you use
    JavaScript form validation, you must validate user input on the server, too, because
    users can bypass the JavaScript if they choose.)

Free download pdf