Web Development with jQuery®

(Elliott) #1

The Various Event Wrapper Methods (^) ❘ 67


FIGURE 3-1


Example 3-1 demonstrates a simple use of the click() method both to attach a callback method and


to trigger the event. Most of jQuery’s event wrapper methods work exactly like this, with just a few


exceptions, which are events such as hover(), which accept multiple callback methods: one for the


mouseover event and one for the mouseout event.


The document ready() event method is also an example of a wrapper event method, which jQuery


creates for the DOMContentLoaded event.


In the example, you attach the callback function. You start by selecting all the

elements in the


document with the class names finderDirectory and finderFile.


$('div.finderDirectory, div.finderFile').click(
function(event)
{
$('div.finderIconSelected')
.removeClass('finderIconSelected');

$('span.finderDirectoryNameSelected')
.removeClass('finderDirectoryNameSelected');

$(this).find('div.finderIcon')
.addClass('finderIconSelected');

$(this).find('div.finderDirectoryName span')
.addClass('finderDirectoryNameSelected');
}
);

When a click event fi res and the callback function is executed, there is a bit of logic that handles


visually selecting a fi le or a folder. You start by removing a selection, which is to say you select the


http://www.it-ebooks.info

Free download pdf