Or you could just use the toggle function: http://api.jquery.com/toggle/
$('#target').toggle(function() {
alert('First handler for .toggle() called.');
}, function() {
alert('Second handler for .toggle() called.');
});
Note: You can have as many toggles as you want, just add more functions:
$('#target').toggle(function() {
alert('1 handler for .toggle() called.');
}, function() {
alert('2 handler for .toggle() called.');
}, function() {
alert('3 handler for .toggle() called.');
}, function() {
alert('4 handler for .toggle() called.');
}, function() {
alert('5 handler for .toggle() called.');
});
[EDIT]
$('a.toggleButton').toggle(function() {
$("#divToSlide").slideDown("fast");
// do something when toggled
}, function() {
$("#divToSlide").slideUp("fast");
// do something when toggled });
});