Thursday, June 4, 2009
These Special Event hooks were changed in 1.4.2. Check out this blog post to see the details about the change.
In jQuery 1.3.3 1.4 there are two new special event hooks: add and remove. These two hooks, unlike setup and teardown, are called for each event being bound. The add hook receives the handler, data, and namespaces as arguments. The remove hook receives the data and namespaces as arguments. The add and remove hooks enable the creation of more complex, even customizable, events.
If you…
Posted in jQuery, jQuery Edge with 7 comments
Thursday, May 28, 2009
In jQuery 1.3.3 1.4 the .hover() method will optionally accept a single method instead of always requiring two methods. This allows you to contain your logic within one method instead of duplicating it among two. I don’t know about you but I’ve avoided using the .hover() method in favor of just manually binding the mouseenter and mouseleave events so that I could use a single function to handle both events. So, lets look at a typical use-case for hover.
$(‘li’)
.hover(function(event) {…
Posted in jQuery, jQuery Edge with 5 comments
Thursday, May 14, 2009
jQuery in the past hasn’t always played well with other windows and documents than the one it was loaded in. However, jQuery is moving in the right direction to help ease the pain of cross window/frame development. There have been several commits recently that make previously window/document dependent methods, well… less dependent. So far .bind(), .css(), .width(), and .height() have all been updated to work with other windows and documents.
So, how might you use this new found jQuery power?…
Posted in jQuery, jQuery Edge with 5 comments
Tuesday, May 12, 2009
Brand new to jQuery SVN is the oft-requested feature of providing a different value for the “this” object in an event callback. Previously jQuery would always send the element as the value of “this” in the callback. You can utilize this new feature by passing the object you’d like to represent “this” in the callback as the last argument to either .bind() or .live(). Lets look at some example code!
The typical use-case for this functionality is that you’ll have an object (or a class) and you wan…
Posted in jQuery, jQuery Edge with 9 comments
Friday, May 8, 2009
In jQuery 1.3.3 1.4 the .live() method will have the ability to pass data along just like you might do with .bind(). The .bind() (and now .live()) method takes an optional second argument called “data”. The data can then be accessed within the event handler by using the event.data property. Here is what the code would look like to use this feature.
// The data
var eventConfig = {
selectedClass: “selected”
};
$(“li”).live(“click”, eventConfig, function( event ) {
// Retreive selectedCla…
Posted in jQuery, jQuery Edge with 5 comments
Thursday, May 7, 2009
Paul Irish and ajpiano (via Google Groups) saw an opportunity to make the .index() method work better for them. Currently the .index() method looks for a given element within the jQuery collection. However, they wanted a quick way to get the index of the current element amongst its siblings. Here is the scenario they laid out.
$(“#sometable th img”).click(function() {
// Need to find out the index of the <th>
// get the <th>
var $th = $(this).parent();
// find the…
Posted in jQuery, jQuery Edge with 4 comments
Wednesday, May 6, 2009
In jQuery 1.3.3 1.4 the .toggleClass() method will have a couple more modes of operation. Currently in jQuery 1.3.2 the .toggleClass() method can only toggle one class name at a time. The new .toggleClass() method will be able to toggle multiple class names and will also be able to toggle all the classes on or off. Here are the different ways you’ll be able to use .toggleClass().
// With the following element
// <div class=”a b c”></div>
// Toggle all classes $(‘div’).toggleClass()…
Posted in jQuery, jQuery Edge with 3 comments