This adds a bit of complexity, but changes more flexibly. If you want to change the duration or add effects to the slide, you do not need to edit the code in 9 places, only 1 or 2. If you do not need additional flexibility, you can simplify some of the code - for example, delete a function getDurationand just hard code 400.
function getDuration() {
return 400;
}
function slideToggleDiv(t, selector) {
t.parent().nextAll(selector).slideToggle(getDuration());
}
function slideUpDiv(selected) {
selected.slideUp(getDuration());
}
$('div.locUpd, div.locDel, div.addLocation').hide();
$('a.edit').click(function(){
slideToggleDiv($(this), 'div.locUpd');
slideUpDiv($('div.locDel, div.addLocation'));
return false;
});
$('a.del').click(function(){
slideToggleDiv($(this), 'div.locDel');
slideUpDiv($('div.locUpd, div.addLocation'));
return false;
});
$('p.buslocadd').click(function(){
slideToggleDiv($(this), 'div.locUpd');
slideUpDiv($('div.locDel, div.locUpd'));
return false;
});
source
share