Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think the problem may have been your use of <code>.replaceWith()</code>. That attempts to replace an element with another, but you've tried to replace an element with text. I think you just want to use <code>.html()</code> instead. </p> <p>Also, you don't need to use the <code>setTimeout()</code> - you can use <code>.delay()</code> instead. And, I think your selectors <code>p:.sleepquestion</code> are probably not right. You can go with this:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function(){ $("#no").click(function() { $("#sleep").animate({"border-width": "10px"}, "fast"); $("#sleepanswer").animate({ opacity: 0 }, "fast"); $("p.sleepquestion").html("That is too bad. Tonight you will sleep better."); moveit(); }); $("#yes").click(function() { $("#sleepanswer").animate({ opacity: 0 }, "fast"); $("p.sleepquestion").html("That is great! A good night sleep is important."); moveit(); }); }); &lt;/script&gt; &lt;script type="text/javascript"&gt; function moveit() { $("#sleep").delay(2000).animate({"left": "10px", "width": "150px"}, "slow"); $("p.sleepquestion").delay(2000).animate({"font-size": "16px"}, "slow"); $("#sleepanswer").delay(2000).animate({ "left": "-9999px"}, "fast"); } &lt;/script&gt; </code></pre> <p>I also changed <code>.replaceWith()</code> to <code>.html()</code> and changed <code>p:.sleepquestion</code> to <code>p.sleepquestion</code>.</p> <p>Your function moveit could also be written like this by putting the timeout inside the function:</p> <pre><code>function moveit() { setTimeout(function() { $("#sleep").animate({"left": "10px", "width": "150px"}, "slow"); $("p.sleepquestion").animate({"font-size": "16px"}, "slow"); $("#sleepanswer").animate({ "left": "-9999px"}, "fast"); }, 2000); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload