dancemc15 dancemc15 - 7 months ago 38
Javascript Question

How do you fade in/fade out same div onclick of image using JQuery?

I want to fade in div onclick of image. I then want to fade out SAME div onclick of image again. Not sure how to go about it. The image and div are separate.

My code can be viewed on JS Fiddle.

$(document).ready(function() {
$("div#img1").click(function() {
$("div#description1").fadeIn('slow', someFunction);
});
});


function someFunction() {
$("div#img1").click(function() {
$("div#description1").fadeOut('slow');
});

Answer

Try

$("div#img1").click(function() {

         $("div#description1").fadeToggle('slow');

      });
 });
Comments