tntran10
tntran10

Reputation: 71

FadeIn/FadeOut Toggle Using One Button

I am currently using this code to try and use a button with a class of .info as a toggle for fading in and fading out text. Right now the animation is running back to back with this code. Is there a way where I click the button once and have the text fade in without it fading out seconds later? The same will apply for fading out when you click the button again.

$('.info').click(function() {
    $('h7').fadeIn(750);
});

$('.info').click(function() {
    $('h7').fadeOut(750);
});         

Upvotes: 7

Views: 12475

Answers (2)

Dom
Dom

Reputation: 40461

$('info').click(function(){
    $('h7').fadeToggle(750);
});

Upvotes: 5

97ldave
97ldave

Reputation: 5249

You can use fadeToggle()

$('.info').click(function() {
    $('h7').fadeToggle(750);
}

Upvotes: 24

Related Questions