Attaching Persistent Event Handlers (^) ❘ 73
{
return;
}
$('div#finderAdditionalFiles > div.finderFile').each(
function()
{
$('div#finderFiles').append(
$(this).clone()
);
}
);
addedAdditionalFiles = true;
}
);
}
);
When the code is loaded into a browser and a dblclick event is dispatched, you can see results simi-
lar to Figure 3-2.
FIGURE 3-2
This example rewrites Example 3-2 to include a persistent event handler and some additional
HTML to test that persistent event handler. The click event handler is attached to the
element
with the id name finderFiles. This is done because that
element will always exist. The second
argument, the selector 'div.finderDirectory, div.finderFile', sets up the persistent event handler.
The event is attached to the
with the id name finderFiles, but the selector argument keeps the
event handler from being executed unless the event originates on an element matching the selector.
$('div#finderFiles').on(
'click',
'div.finderDirectory, div.finderFile',
function(event)
{
$('div.finderIconSelected')