0

I have two divs in my html page and I want to show one div on hide of other and show other on hide of first automatically after each 5 seconds. I am writing this in my document.ready but it is not working. It only hides first div and shows it and then it does nothing.

  $("#free-trial-link").show().delay(5000).queue(function(n) {
      $(this).hide(); n();
  });


  $('#free-trial-link').fadeIn(function() {
        $('#record-call-link').fadeIn();   
  });

  $('#record-call-link').fadeIn(function() {
        $('#free-trial-link').fadeIn();   
  });

Markup is:

   <div class="container_content" style="padding-top: 10px;">
                                                    <p class="date_day" id="p-free-trial-link" style="display: none">
                                                        <img id="free-trial-link" style="cursor: pointer;" src="images/tial-icon.png" width="32"
                                                            height="32"><br>
                                                        Free Trial
                                                    </p>
                                                    <p class="date_day" style="text-align: right; margin-top: 25px;" id="p-record-call-link">
                                                        <img id="record-call-link" style="position: inherit; cursor: pointer;" src="images/record-icon.png"
                                                            width="32" height="32"><br>
                                                        Record a Call
                                                    </p>
                                                    <div class="clear-n">
                                                    </div>
                                                </div>
DotnetSparrow
  • 27,428
  • 62
  • 183
  • 316
  • Please check this [link][1]. Hope this is what you want [1]: http://stackoverflow.com/questions/914951/show-and-hide-divs-at-a-specific-time-interval-using-jquery – Roger Apr 20 '13 at 11:43

2 Answers2

1

Try

<div class="container_content" style="padding-top: 10px;">
    <p class="date_day" id="p-free-trial-link" style="display: none">
        <img id="free-trial-link" style="cursor: pointer;" src="images/tial-icon.png" width="32"
        height="32" /><br />
        Free Trial
    </p>
    <p class="date_day" style="text-align: right; margin-top: 25px; display: none" id="p-record-call-link">
        <img id="record-call-link" style="position: inherit; cursor: pointer;" src="images/record-icon.png"
        width="32" height="32" /><br />
        Record a Call
    </p>
    <div class="clear-n">
    </div>
</div>

And

$(function(){
    function showTrial(){
        $("#p-free-trial-link").show().delay(5000).hide(function(){
            showCall();
        });
    }

    function showCall(){
        $("#p-record-call-link").show().delay(5000).hide(function(){
            showTrial()
        });
    }

    showTrial()
});

Demo: Fiddle

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
0

you can use .toggle() in jQuery

PSR
  • 39,804
  • 41
  • 111
  • 151