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"
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
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
cool js thing for the day
JavaScript framework example site
AJS Lecture 4: jQuery Part 2
By Ryan Lewis
AJS Lecture 4: jQuery Part 2
- 620