Hi there, I am repeating an IF ELSE statement like so
$('#accountLoginButton').click(function() {
if($('#topSubscribe').is(":visible")) {
$('#topSubscribe').slideUp(function(){
if ($('#topLogin').is(":hidden"))
{
$('#topLogin').slideDown("fast");
} else {
$('#topLogin').slideUp("fast");
}
});
} else {
if ($('#topLogin').is(":hidden"))
{
$('#topLogin').slideDown("fast");
} else {
$('#topLogin').slideUp("fast");
}
}
});
$('#subscribeTopButton').click(function() {
if($('#topLogin').is(":visible")) {
$('#topLogin').slideUp(function(){
if ($('#topSubscribe').is(":hidden"))
{
$('#topSubscribe').slideDown("fast");
} else {
$('#topSubscribe').slideUp("fast");
}
});
} else {
if ($('#topSubscribe').is(":hidden"))
{
$('#topSubscribe').slideDown("fast");
} else {
$('#topSubscribe').slideUp("fast");
}
}
});
Basically 2 buttons operating like tabs to show/hide stuff.
As you can see I literally have the same code being repeated in a few different ways a couple times. I have a feeling i could somehow get this down to a few lines of code but my javascript understanding is a bit shady in general.
How do I trim this down the most?