0

Hi everyone anyone can help me in my code.

$(document).ready(function() {
     var circle = $('.circle');
     $(".send a").click(function(e) {
      e.preventDefault();
     $('.wrap').css('display', 'block');

        if (circle.hasClass('bounceInLeft')) {
         circle.removeClass('bounceInLeft').addClass('bounceOutRight');

          }
           else 
          {

         $('.circle').addClass('animated bounceOutRight');
         circle.removeClass('bounceOutRight').addClass('bounceInLeft');
           }

      });

  });

When you click .send a then .wrap will display:block . How can i add second click .send a then .wrap will display none? I know it should to be like this:

$('.wrap').css('display', 'none'); but i don't know where i can write this code...

.wrap {
  max-width: 400px;
  margin: 4em auto;
  text-align: center;
  display:none;
  background-color:#fff;
}

2 Answers 2

1

You could use .toggle() to toggle the visibility of the element on each click.

$(".send a").on('click', function(e) {
    $('.wrap').toggle();
    // ..
});

Alternatively, it would be better to use .toggleClass(), and add/remove a class such as .hide:

.hide {
    display: none; /* You may wish to increase the specificity.. */
}
$(".send a").on('click', function(e) {
    $('.wrap').toggleClass('hide');
    // ..
});

If you are insistent upon manually adding/removing inline CSS, you would just need to use a conditional statement like:

$('.wrap').is(':hidden') ? $('.wrap').show() : $('.wrap').hide();
Sign up to request clarification or add additional context in comments.

1 Comment

i still add this but when use this then my animation not working on that time can you check this demo from codepen.io DEMO
0

Demo

What I added was a variable that finds out how many times you have clicked the anchor element.

This way is very simple, and I hope that it works for you.
Good luck!

1 Comment

thanks for your answer but if you can check my DEMO then you can see what is my problem. DEMO

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.