John Resig jQuery jQuery is designed for protyping. Can layer functionality onto the page using CSS (classes, etc.) also makes it easy to seperate behavior. Basic jQuery: find element and perform action $("div").addClass("special"); * $: jQuery Object (also "jQuery" for namespace) * "div": string to find some element (CSS expression) * addClass: command * "special": name of class Element selection via full CSS 1, 2, 3 selector support, which is better than most browsers. Does NOT rely on browser selector, so good across browsers, etc. Can also do enhanced features. * Child selectors, "div > div": only divs that are a children of div * Has, "div:has(div)": divs that have a div inside of them * attribute, "a[target]": all a's that have a target attribute * attribute, "a[target-_blank]": all a's that have a target attribute set to blank If an element doesn't match on the page, it's silently ignored. This matches CSS behavior in good ways (forgiving) and bad ways (can make it hard t debug). Things to do with elements. DOM manipulation (append, prepend, remove), events, effects (hide, show, slide, etc.), AJAX (get, load, etc.). These are the methods of the object. DOM: ".append", ".css". Events: .submit (arg: function that's executed when submit is fired), .click (likewise, return value tells browser whether this should chain (true) or stop (false), which lets you use unobtrusive Javascript), Animation: .slideDown, .animate (accepts CSS and animates changes), .hide (takes a callback). Inside callbacks, $(this) is the individual element inside the callback (since selectors can get many results). AJAX: .load (smart enough to load external HTML once no matter how many places it gets written). .load allows use of selectors inline, which are applied to the incoming document. E.g. $("#body").load("sample.html div > h1") will only grab the

's inside div's from the sample.html HTML. jQuery can chain actions: $().hide().css("color", "blue")... This works by returning self, so the query only happens once. Some items do NOT return self, for example .children returns the elements children, .end terminates the current chain and returns to the previous elements on the stack. E.g. ${"ul"}.children(...).css().end().hide(...) First css() modifies the children of ul, hide() modifies the ul elements themselves. The stack manipulation means that each query is only done once. This has a small performance benefit, but John favors it because of its programming benefit: only one selection with many operations. Can also save the results of a query and then use it later to apply lots of actions. Can also use jQuery to do the unobtrusive late loading of javascript: ${document}.readu(function(){/* code */}) Performs manipulation after HTML is loaded but before rendering. Normally all jQuery will be inside such a construct. Why jQuery? * Fully documented * Community * Plug-in architecture * Small file size (15k) * Fully cross browser * Unobtrusive-ness allows easy migration from prototype -> finished Examples: Apple's accordian menus. Easiest way to use is to use FireBug as REPL (assuming you load jQuery in head). E.g. load page and ">>> $("h3.drawer-handle")" Can then build up code inline with selectors, etc. Can also use plug-ins. In his example, he uses HoverIntent to force hover before firing event. Include with