Muhammad Mubashir Muhammad Mubashir - 7 months ago 25
Javascript Question

Jquery FadeIn function not working in first time

I m using the below jQuery to hide a

div
on click of a button. But I found a problem.
fadeIn
is not working the very first time, but the second time its working. How to fix it?

<script>
$(".get-btn").click(function() {
$(".container").css('z-index', '40');
$('.container').fadeOut(500)
});
</script>

<script>
$(".close-btn").click(function() {
$(".container-sec").css('z-index', '0');
$('.container').fadeIn(500)
});
</script>


here is the JSfiddle: http://jsfiddle.net/mmubashirs/zoctx3f3/

Answer

Try this:

$( document ).ready(function() {
  $( ".get-btn" ).click(function() {
    $(".container").css('z-index', '40');
    $('.container').fadeOut(500);
  });

  $( ".close-btn" ).click(function() {
    $(".container-sec").css('z-index', '0');
    $('.container').fadeIn(500);
  });
});

Comments