Skip to content
Advertisement

How to make a simple fade in/out panel with jQuery?

I’m trying to make a text fade in and fade out, alternately, as you click a button, using jQuery. I came up with this code:

JavaScript
JavaScript

That works only once (fades in first click, fades out second) and the button stops working forever.

If I comment out line 5, the button works once and everytime I press it again, the text fades in and out at the same time, which is not what I want.

What am I doing wrong?

Advertisement

Answer

There is a method fadeToggle() which toggles between fadeIn and fadeOut.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement