jquery

part 2


class overview

  • Homework Solution
  • .css()
  • Callback Functions
  • $.each()
  • instanceof
  • Homework Overview

.css()

Returns or modifies the style property of an object.
//working with this element: //<div id='item'></div>//set a CSS style  var item = $('#item');  item.css('font-size', 24);//<div id='item' style="font-size:24px"></div>//get a CSS style  item.css('font-size');// > "24px"
.css() documentation

callback functions

  • Because Functions are a first-class object in JavaScript, you can pass them as arguments into Functions. Then, they can be called at a later time.
  • You can't just write code, you have to wrap it in a function declaration. This creates an anonymous function (because it has no name).
  • A lot of jQuery uses callback functions.
  • Perfect for asynchronous operations.
  • Don't be afraid of them (they are your friend).
  • Ryan, do a callback demo!

jquery.each()

  • Sort of a jQuery foreach.
  • Pass an array or object as the first parameter.
  • Pass a callback function as the second parameter.
  • Callback function passes in the current index & value 



jQuery.each() documentation

instanceof

  • Use instead of 'typeof', which is too generic.
  • Tests for constructors on an objects prototype chain.
  • Can be used for custom constructors.
 function constructObj() {}; var realObj = new constructObj(); realObj instanceof constructObj; // > true realObj instanceof Array; // > false realObj instanceof Object; // > true

instanceof documentation

cool js thing for the day

TodoMVC
JavaScript framework example site
Made with Slides.com