Limiting and Ending Events
The mouseout
scenario just described illustrates the need to constrain the scope of an event. While .hover()
handles this specific case, we will encounter other situations in which we need to limit an event spatially (preventing the event from being sent to certain elements) or temporally (preventing the event from being sent at certain times).
Preventing Event Bubbling
We have already seen one situation in which event bubbling can cause problems. To show a case in which .hover()
does not help our cause, we’ll alter the collapsing behavior we implemented earlier.
Suppose we wish to expand the clickable area that triggers the collapsing or expanding of the style switcher. One way to do this is to move the event handler from the label to the containing <div>
element:
$(document).ready(function() {
$('#switcher').click(function() {
$('#switcher .button').toggleClass('hidden');
});
});
This alteration makes the entire area of the style switcher clickable to...