Like structuring a page with a bunch of <span style="display: block">
DOM Scripting / Web Standards
Unobtrusive JavaScript
Tests features, not browsers
Unobtrusive
Content
Presentation
Behavior
Tests Features
var x,y;
if (self.innerHeight) { // all except Explorer
x = self.innerWidth;
y = self.innerHeight;
}
else if (document.documentElement &&
document.documentElement.clientHeight) {
// Explorer 6 Strict Mode
x = document.documentElement.clientWidth;
y = document.documentElement.clientHeight;
}
else if (document.body) { // other Explorers
x = document.body.clientWidth;
y = document.body.clientHeight;
}
Along Came jQuery
(and other libraries)
Open-source JavaScript library
Unobtrusive from the ground up
Quick, terse syntax
Simplifies interaction between HTML & JavaScript
jQuery Is Open Source
Dual-licensed: MIT and GPL
Take your pick
Most people pick MIT
jQuery Is Open Source
Copyright (c) 2009 John Resig, http://jquery.com/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND …
jQuery Is Unobtrusive
Content
Presentation
Behavior
jQuery Has Quick, Terse Syntax
var x = $(window).width();
var y = $(window).height();
jQuery Simplifies Interaction
Find Some Elements
Do Something With Them
Find Some Elements
Full CSS Selector 1-3 Support
Better CSS Selector support than most browsers
$
$ == jQuery
$( )
$() == jQuery()
$( 'div' )
Do Something With Them
Let elements "listen" for something to happen…
the document is ready
user does something
another "listener" acts
a certain amount of time elapses
Do Something With Them
…and then do something
Manipulate elements create, insert, move, remove. modify attributes, dimensions, etc.
Animate elements slide, fade, move, etc.
Communicate with the server send and receive data (ajax, ahah)
Reference Scripts
Reference scripts after styles
Reference custom scripts come after jQuery core
Reference plugins in between jQuery core and custom scripts
Reference scripts in <head> or just before </body>
Download jQuery …
from jquery.com
… or Use a CDN
from Google: http://code.google.com/apis/ajaxlibs
from Microsoft: http://www.asp.net/ajax/cdn/
Reference Scripts
<head>
<!-- etc. -->
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<!-- etc. -->
<script src="/scripts/jquery.js"></script>
<script src="/scripts/my-custom-script.js"></script>
</body>