Book Image

PHP Ajax Cookbook

Book Image

PHP Ajax Cookbook

Overview of this book

Table of Contents (16 chapters)
PHP Ajax Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Triggering JavaScript early/on DOM load


In Web 2.0 websites that have containers and animations, we'd want the JavaScript code to get executed as quickly as possible, so that the users won't see a flickering effect when we apply hide, show, or animation effects. Also, when we handle any events through JavaScript or JavaScript frameworks, we'd want the events such as click, change, and so on get applied to the DOM as quickly as possible.

Getting ready

Earlier, JavaScript developers mixed JavaScript and HTML together. This practice is called inline scripting. As the Web was evolving, more standards and practices came up. Unobtrusive JavaScript practice generally means that JavaScript code is separated from markup code and JavaScript is handled in an unobtrusive manner.

Here's some quick code written to alert the user with the message Enter your name!, when the name field is clicked:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd...