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...